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