rapid-spreadjs 1.0.53 → 1.0.54

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.esm.js CHANGED
@@ -806,9 +806,11 @@ const BusinessUtils = {
806
806
  * @param cellRange 单元格范围JSON对象,格式为:{row:0, col:0, rowCount:2, colCount:5}
807
807
  * @param curDefaultPointCount 本次默认点数
808
808
  * @param lastDefaultPointCount 上次默认点数,默认为:0(0代表首次创建)
809
+ * @param isAutoFillFirstCellNumber 是否自动填充第一个单元格为序号数字,默认为:false
810
+ * @param created 创建完成后的回调函数,第一个参数为循环后的所有单元格范围对象(格式为:{row:0, col:0, rowCount:10, colCount:5}),第二个参数为所有循环行的单元格二维数组对象
809
811
  * @param rowHeight 创建的行高度,默认为:24(单位为像素)
810
812
  */
811
- dynamicCreateCyclicRows: (GC, spread, cellRange, curDefaultPointCount, lastDefaultPointCount = 0, rowHeight = 24) => {
813
+ dynamicCreateCyclicRows: (GC, spread, cellRange, curDefaultPointCount, lastDefaultPointCount = 0, isAutoFillFirstCellNumber = false, created = null, rowHeight = 24) => {
812
814
  // 不进行动态创建行
813
815
  if ((curDefaultPointCount <= 1 && lastDefaultPointCount == 0) || (curDefaultPointCount == lastDefaultPointCount && lastDefaultPointCount > 0)) {
814
816
  return;
@@ -867,12 +869,41 @@ const BusinessUtils = {
867
869
  else if (curDefaultPointCount > 1 && lastDefaultPointCount == 0) {
868
870
  addRowsFun(cellRange.row + cellRange.rowCount, (curDefaultPointCount - 1) * cellRange.rowCount, curDefaultPointCount - 1);
869
871
  }
872
+ // 循环后的所有单元格范围
873
+ const cyclicCellsRangeObj = sheet.getRange(cellRange.row, cellRange.col, curDefaultPointCount * cellRange.rowCount, cellRange.colCount);
870
874
  // 判断要循环的单元格最后一行是否为表格的末尾行,如果是,则在循环创建单元行的最后一行的时候,下边框线位细线样式
871
875
  if (isCyclicLastRowIsSheetLastRow) {
872
876
  // 设置所有内边框线为细线样式
873
- sheet
874
- .getRange(cellRange.row, cellRange.col, curDefaultPointCount * cellRange.rowCount, cellRange.colCount)
875
- .setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.thin), { inside: true });
877
+ cyclicCellsRangeObj.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.thin), { inside: true });
878
+ }
879
+ // 循环后的所有单元格范围JSON对象
880
+ const cyclicCellsRange = {
881
+ row: cyclicCellsRangeObj.row,
882
+ col: cyclicCellsRangeObj.col,
883
+ rowCount: cyclicCellsRangeObj.rowCount,
884
+ colCount: cyclicCellsRangeObj.colCount,
885
+ };
886
+ // 自动填充第一个单元格为序号数字
887
+ const allCells = SheetUtils.getAllCellObjsByRanges(sheet, [cyclicCellsRange]);
888
+ const allCellsByRowObj = groupByJson(allCells, 'row');
889
+ let allCellsByRow = [];
890
+ if (isAutoFillFirstCellNumber) {
891
+ forEachJson(allCellsByRowObj, (value, key, source) => {
892
+ allCellsByRow.push(value);
893
+ });
894
+ let number = 0;
895
+ allCellsByRow.forEach((rowCells, rowIndex) => {
896
+ rowCells.forEach((rowCell, cellIndex) => {
897
+ if (cellIndex == 0) {
898
+ number++;
899
+ sheet.setValue(rowCell.row, rowCell.col, number);
900
+ }
901
+ });
902
+ });
903
+ }
904
+ // 创建完成后的回调函数
905
+ if (created != null && created != undefined && typeof created === 'function') {
906
+ created(cyclicCellsRange, allCellsByRow);
876
907
  }
877
908
  // 恢复绘制
878
909
  sheet.resumePaint();