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.cjs.js CHANGED
@@ -828,9 +828,11 @@ const BusinessUtils = {
828
828
  * @param cellRange 单元格范围JSON对象,格式为:{row:0, col:0, rowCount:2, colCount:5}
829
829
  * @param curDefaultPointCount 本次默认点数
830
830
  * @param lastDefaultPointCount 上次默认点数,默认为:0(0代表首次创建)
831
+ * @param isAutoFillFirstCellNumber 是否自动填充第一个单元格为序号数字,默认为:false
832
+ * @param created 创建完成后的回调函数,第一个参数为循环后的所有单元格范围对象(格式为:{row:0, col:0, rowCount:10, colCount:5}),第二个参数为所有循环行的单元格二维数组对象
831
833
  * @param rowHeight 创建的行高度,默认为:24(单位为像素)
832
834
  */
833
- dynamicCreateCyclicRows: (GC, spread, cellRange, curDefaultPointCount, lastDefaultPointCount = 0, rowHeight = 24) => {
835
+ dynamicCreateCyclicRows: (GC, spread, cellRange, curDefaultPointCount, lastDefaultPointCount = 0, isAutoFillFirstCellNumber = false, created = null, rowHeight = 24) => {
834
836
  // 不进行动态创建行
835
837
  if ((curDefaultPointCount <= 1 && lastDefaultPointCount == 0) || (curDefaultPointCount == lastDefaultPointCount && lastDefaultPointCount > 0)) {
836
838
  return;
@@ -889,12 +891,41 @@ const BusinessUtils = {
889
891
  else if (curDefaultPointCount > 1 && lastDefaultPointCount == 0) {
890
892
  addRowsFun(cellRange.row + cellRange.rowCount, (curDefaultPointCount - 1) * cellRange.rowCount, curDefaultPointCount - 1);
891
893
  }
894
+ // 循环后的所有单元格范围
895
+ const cyclicCellsRangeObj = sheet.getRange(cellRange.row, cellRange.col, curDefaultPointCount * cellRange.rowCount, cellRange.colCount);
892
896
  // 判断要循环的单元格最后一行是否为表格的末尾行,如果是,则在循环创建单元行的最后一行的时候,下边框线位细线样式
893
897
  if (isCyclicLastRowIsSheetLastRow) {
894
898
  // 设置所有内边框线为细线样式
895
- sheet
896
- .getRange(cellRange.row, cellRange.col, curDefaultPointCount * cellRange.rowCount, cellRange.colCount)
897
- .setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.thin), { inside: true });
899
+ cyclicCellsRangeObj.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.thin), { inside: true });
900
+ }
901
+ // 循环后的所有单元格范围JSON对象
902
+ const cyclicCellsRange = {
903
+ row: cyclicCellsRangeObj.row,
904
+ col: cyclicCellsRangeObj.col,
905
+ rowCount: cyclicCellsRangeObj.rowCount,
906
+ colCount: cyclicCellsRangeObj.colCount,
907
+ };
908
+ // 自动填充第一个单元格为序号数字
909
+ const allCells = SheetUtils.getAllCellObjsByRanges(sheet, [cyclicCellsRange]);
910
+ const allCellsByRowObj = rapidUtils.groupByJson(allCells, 'row');
911
+ let allCellsByRow = [];
912
+ if (isAutoFillFirstCellNumber) {
913
+ rapidUtils.forEachJson(allCellsByRowObj, (value, key, source) => {
914
+ allCellsByRow.push(value);
915
+ });
916
+ let number = 0;
917
+ allCellsByRow.forEach((rowCells, rowIndex) => {
918
+ rowCells.forEach((rowCell, cellIndex) => {
919
+ if (cellIndex == 0) {
920
+ number++;
921
+ sheet.setValue(rowCell.row, rowCell.col, number);
922
+ }
923
+ });
924
+ });
925
+ }
926
+ // 创建完成后的回调函数
927
+ if (created != null && created != undefined && typeof created === 'function') {
928
+ created(cyclicCellsRange, allCellsByRow);
898
929
  }
899
930
  // 恢复绘制
900
931
  sheet.resumePaint();