rapid-spreadjs 1.0.18 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -7311,7 +7311,18 @@ const SheetUtils = {
7311
7311
  sheet.setSelection(cellObj.row, cellObj.col, cellObj.rowCount, cellObj.colCount);
7312
7312
  },
7313
7313
  /**
7314
- * 获取某工作表中某范围集合中所有的单元格坐标对象集合
7314
+ * 获取某工作表中某个范围中所有的单元格坐标对象集合
7315
+ * 该方法适用的场景如:手动选择了某个单元格范围,在这个范围中可能包含独立的单元格,也可能包含合并的单元格,这时候就需要用到如下方法获取到所有单元格对象
7316
+ * @param sheet 工作表实例
7317
+ * @param selectRange 单元格范围,格式如:{ row: 0, col: 0, rowCount: 2, colCount: 2 }
7318
+ * @param isMulColOrder 是否按照多列的顺序排序单元格(true:按照第一列从上到下、第二列从上到下……的顺序获取单元格数据、false:按照第一行从左到右、第二行从左到右……的顺序获取单元格数据)
7319
+ * @returns 返回数组集合,格式如:[{ row: 0, col: 0, rowCount: 1, colCount: 1 }]
7320
+ */
7321
+ getAllCellObjsByRange: (sheet, selectRange, isMulColOrder = false) => {
7322
+ return SheetUtils.getAllCellObjsByRanges(sheet, [selectRange], isMulColOrder);
7323
+ },
7324
+ /**
7325
+ * 获取某工作表中多个范围集合中所有的单元格坐标对象集合
7315
7326
  * 该方法适用的场景如:手动选择了很多个单元格范围,在这些范围中可能包含独立的单元格,也可能包含合并的单元格,这时候就需要用到如下方法获取到所有单元格对象
7316
7327
  * @param sheet 工作表实例
7317
7328
  * @param selectRanges 单元格范围集合,格式如:[{ row: 0, col: 0, rowCount: 2, colCount: 2 }]
@@ -7432,6 +7443,41 @@ const SheetUtils = {
7432
7443
  const sheet = spread.getActiveSheet();
7433
7444
  return SheetUtils.getSheetSelectVals(sheet, isMulColOrder, nullUndefinedReplaceVal);
7434
7445
  },
7446
+ /**
7447
+ * 获取某工作表指定范围单元格的值集合(二维数组,格式如:[[1,2,3],[4,5,6]])
7448
+ * @param sheet 工作表实例
7449
+ * @param cellRange 单元格范围
7450
+ * @param groupType 分组字段属性(row或col),默认为:row
7451
+ * @param nullUndefinedReplaceVal 如果单元格的值为null或undefined,则将其替换为该值(如果不传入该参数,则不替换)
7452
+ * @returns 返回某工作表指定范围单元格的值集合(二维数组,格式如:[[1,2,3],[4,5,6]])
7453
+ */
7454
+ getSheetRangeValsByGroup: (sheet, cellRange, groupType = 'row', nullUndefinedReplaceVal) => {
7455
+ // 暂停绘制
7456
+ sheet.suspendPaint();
7457
+ const valCells = SheetUtils.getAllCellObjsByRange(sheet, cellRange);
7458
+ // 按照JSON数组中某个字段进行分组(groupType为row或col)
7459
+ const groupByCells = rapidUtils.groupByJson(valCells, groupType);
7460
+ // 最终返回结果(二维数组)
7461
+ const retVals = [];
7462
+ // 遍历分组JSON对象(groupByCells的格式为:{key1: [cell1, cell2, ...], key2: [cell1, cell2, ...], ...})
7463
+ rapidUtils.forEachJson(groupByCells, (curGroupCells, key, source) => {
7464
+ // 当前按照row或col分组的单元格的值集合
7465
+ const curVals = [];
7466
+ // 遍历当前分组的所有单元格
7467
+ rapidUtils.forEachJson(curGroupCells, (item, index, source) => {
7468
+ let cellVal = sheet.getValue(item.row, item.col);
7469
+ // 如果cellVal为null或undefined,并且nullUndefinedReplaceVal不为null或undefined,则将cellVal替换为nullUndefinedReplaceVal
7470
+ if (nullUndefinedReplaceVal != null && nullUndefinedReplaceVal != undefined && (cellVal === null || cellVal === undefined)) {
7471
+ cellVal = nullUndefinedReplaceVal;
7472
+ }
7473
+ curVals.push(cellVal);
7474
+ });
7475
+ retVals.push(curVals);
7476
+ });
7477
+ // 恢复绘制
7478
+ sheet.resumePaint();
7479
+ return retVals;
7480
+ },
7435
7481
  /**
7436
7482
  * 获取单元格类型名称
7437
7483
  * @param GC GC对象
@@ -7699,11 +7745,39 @@ const SheetUtils = {
7699
7745
  },
7700
7746
  };
7701
7747
 
7702
- // 导出Excel文件所需的第三方包
7703
7748
  /**
7704
7749
  * SpreadJS工作簿工具函数属性
7705
7750
  */
7706
7751
  const WorkbookUtils = {
7752
+ /**
7753
+ * 加载在线sjs文件
7754
+ * @param spread 工作簿对象
7755
+ * @param fileUrl 在线sjs文件地址
7756
+ * @param succFunc 文件打开成功后的回调函数,返回的第一个参数为spread工作簿对象
7757
+ * @param errorFunc 文件打开失败后的回调函数,返回的第一个参数为错误信息
7758
+ */
7759
+ loadSjsFile: (spread, fileUrl, succFunc, errorFunc) => __awaiter(void 0, void 0, void 0, function* () {
7760
+ // 获取文件响应结果
7761
+ const response = yield fetch(fileUrl, { method: 'GET' });
7762
+ // 获取成功
7763
+ if (response.ok) {
7764
+ // 文件的字节流对象
7765
+ const blob = yield response.blob();
7766
+ // 将Blob转换为File或Blob对象
7767
+ new File([blob], 'template.sjs', { type: 'application/octet-stream' });
7768
+ const sjsBlob = new Blob([blob], { type: 'application/zip' });
7769
+ // SpreadJS打开文件
7770
+ spread.open(sjsBlob, () => {
7771
+ if (typeof succFunc === 'function') {
7772
+ succFunc(spread);
7773
+ }
7774
+ }, (e) => {
7775
+ if (typeof errorFunc === 'function') {
7776
+ errorFunc(e);
7777
+ }
7778
+ });
7779
+ }
7780
+ }),
7707
7781
  /**
7708
7782
  * 打印所有工作表
7709
7783
  * @param GC GC对象
@@ -7770,20 +7844,11 @@ const WorkbookUtils = {
7770
7844
  * @param spread 原始Spread对象
7771
7845
  * @param fileName 导出的文件名称,不传则为第一个工作表的名称
7772
7846
  */
7773
- exportToExcel: (GC, spread, fileName = "") => {
7847
+ exportToExcel: (GC, spread, fileName = '') => {
7774
7848
  // 导出模板为JSON对象,此处设置了参数includeBindingSource,改参数代表包含数据绑定的值
7775
7849
  const json = spread.toJSON({ includeBindingSource: true });
7776
7850
  // 需要移除的自定义公式名称集合(该变量的作用是,在导出Excel前,将工作簿中所有的自定义公式移除掉,其他内置的公式保留)
7777
- const removeCustomFormulas = [
7778
- "YJMAX",
7779
- "YJMIN",
7780
- "YJMID",
7781
- "YJGETNUM",
7782
- "YJGETS",
7783
- "YJGETCV",
7784
- "YJINTERPOLATIONMETHOD",
7785
- "YJINTERPOLATIONMETHOD_Y",
7786
- ];
7851
+ const removeCustomFormulas = ['YJMAX', 'YJMIN', 'YJMID', 'YJGETNUM', 'YJGETS', 'YJGETCV', 'YJINTERPOLATIONMETHOD', 'YJINTERPOLATIONMETHOD_Y'];
7787
7852
  // 临时工作簿
7788
7853
  const tempSpread = new GC.Spread.Sheets.Workbook();
7789
7854
  tempSpread.fromJSON(json);
@@ -7801,9 +7866,7 @@ const WorkbookUtils = {
7801
7866
  // 获取单元格的公式
7802
7867
  const cellFormula = sheet.getFormula(i, j);
7803
7868
  // 如果cellFormula不为null或undefined,则说明该单元格引用了公式
7804
- if (cellFormula != null &&
7805
- cellFormula != undefined &&
7806
- removeCustomFormulas.some((item) => cellFormula.indexOf(item) > -1)) {
7869
+ if (cellFormula != null && cellFormula != undefined && removeCustomFormulas.some((item) => cellFormula.indexOf(item) > -1)) {
7807
7870
  // 获取单元格的值
7808
7871
  const cellVal = sheet.getValue(i, j);
7809
7872
  // 移除单元格引用的公式
@@ -7818,7 +7881,7 @@ const WorkbookUtils = {
7818
7881
  }
7819
7882
  // 恢复绘制
7820
7883
  tempSpread.resumePaint();
7821
- if (fileName == "") {
7884
+ if (fileName == '') {
7822
7885
  fileName = tempSpread.getSheet(0).name();
7823
7886
  }
7824
7887
  let options = {