rapid-spreadjs 1.0.39 → 1.0.40

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
@@ -573,6 +573,58 @@ const SheetUtils = {
573
573
  // // 或者使用SpreadJS提供的方法rangeToFormula
574
574
  // return GC.Spread.Sheets.CalcEngine.rangeToFormula(cellRange);
575
575
  },
576
+ /**
577
+ * 获取工作表中所有纯值或公式单元格的范围选择字符串
578
+ * @param sheet 工作表对象
579
+ * @param isFormulaCells 是否获取公式单元格,默认为:false
580
+ */
581
+ getCellsRangeStr: (sheet, isFormulaCells = false) => {
582
+ const range = { row: 0, col: 1, rowCount: sheet.getRowCount(), colCount: 77 };
583
+ // 所有单元格对象集合
584
+ const allCells = SheetUtils.getAllCellObjsByRanges(sheet, [range]);
585
+ // 最终需要的单元格对象集合
586
+ let retCells = [];
587
+ // 遍历所有单元格
588
+ allCells.forEach((cell) => {
589
+ const value = sheet.getValue(cell.row, cell.col);
590
+ const formula = sheet.getFormula(cell.row, cell.col);
591
+ // 非公式+有值(非空) || 公式
592
+ if ((!isFormulaCells && !formula && value !== null && value !== undefined && value !== '') || (isFormulaCells && formula)) {
593
+ retCells.push(cell);
594
+ }
595
+ });
596
+ // 辅助函数:将列索引转为大写字母(如 0->A, 1->B, 26->AA)
597
+ const indexToAlpha = (index) => {
598
+ let alpha = '';
599
+ while (index >= 0) {
600
+ alpha = String.fromCharCode(65 + (index % 26)) + alpha;
601
+ index = Math.floor(index / 26) - 1;
602
+ if (index < 0)
603
+ break;
604
+ }
605
+ return alpha;
606
+ };
607
+ // Sheet名称
608
+ const sheetName = sheet.name();
609
+ // 处理每个单元格/区域
610
+ const cellStrings = retCells.map((cell) => {
611
+ // 起始列字母
612
+ const colAlpha = indexToAlpha(cell.col);
613
+ // 起始行号(从1计数)
614
+ const startRow = cell.row + 1;
615
+ // 合并单元格只返回左上角单元格
616
+ const isMerged = cell.rowCount > 1 || cell.colCount > 1;
617
+ // 处理区域范围(合并单元格只返回左上角)
618
+ if (isMerged) {
619
+ return `${sheetName}!${colAlpha}${startRow}`;
620
+ }
621
+ // 处理单单元格
622
+ else {
623
+ return `${sheetName}!${colAlpha}${startRow}`;
624
+ }
625
+ });
626
+ return '=' + cellStrings.join(',');
627
+ },
576
628
  };
577
629
 
578
630
  /**