rapid-spreadjs 1.0.170 → 1.0.172

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
@@ -1447,7 +1447,7 @@ const BusinessUtils = {
1447
1447
  }
1448
1448
  }
1449
1449
  let rowObjs = { row: parseInt(rowIndexKey), rows: curRowIndexs, cells: cellItems, hasValue: curRowHasValue };
1450
- if (seqColSpanObj && !rowCells.some((x) => x.rowSpan == seqColSpanObj.row)) {
1450
+ if (!rowCells.some((x) => x.rowSpan == seqColSpanObj.row)) {
1451
1451
  let rowIndexs = [];
1452
1452
  const seqColSpanRowSpan = sheet.getSpans({ row: seqColSpanObj.row, col: 1, rowCount: 1, colCount: 1 })[0];
1453
1453
  for (let i = 0; i < seqColSpanRowSpan.rowCount; i++) {
@@ -1460,10 +1460,8 @@ const BusinessUtils = {
1460
1460
  });
1461
1461
  }
1462
1462
  else {
1463
- if (seqColSpanObj) {
1464
- let curRow = rowCells.find((x) => x.rowSpan == seqColSpanObj.row);
1465
- curRow.rows.push(rowObjs);
1466
- }
1463
+ let curRow = rowCells.find((x) => x.rowSpan == seqColSpanObj.row);
1464
+ curRow.rows.push(rowObjs);
1467
1465
  }
1468
1466
  });
1469
1467
  // 有值和没有值的行索引集合
@@ -1503,16 +1501,26 @@ const BusinessUtils = {
1503
1501
  });
1504
1502
  }
1505
1503
  });
1506
- let serNum = 0;
1507
- hasValueRowsSer.forEach((rowIndex, index) => {
1508
- const curVal = sheet.getValue(rowIndex, 1);
1509
- // 检查第一个单元格的值是否包含非数字字符,有非数字字符的时候代表不填充序号
1510
- if (!/^(?!\d+$)[\u4e00-\u9fa5a-zA-Z0-9!@#$%^&*()_+[\]{};':",.\/?\\|-]+$/.test(curVal)) {
1511
- serNum++;
1504
+ // 禁用的时候,将所有的序号重新设置
1505
+ if (!isEnable) {
1506
+ rowCells.forEach((rowObj, index) => {
1512
1507
  // 设置序号列单元格的值(1、2、3...的格式)
1513
- sheet.setValue(rowIndex, 1, serNum);
1514
- }
1515
- });
1508
+ sheet.setValue(rowObj.rowSpan, 1, index + 1);
1509
+ });
1510
+ }
1511
+ // 启用的时候
1512
+ else {
1513
+ let serNum = 0;
1514
+ hasValueRowsSer.forEach((rowIndex, index) => {
1515
+ const curVal = sheet.getValue(rowIndex, 1);
1516
+ // 检查第一个单元格的值是否包含非数字字符,有非数字字符的时候代表不填充序号
1517
+ if (!/^(?!\d+$)[\u4e00-\u9fa5a-zA-Z0-9!@#$%^&*()_+[\]{};':",.\/?\\|-]+$/.test(curVal)) {
1518
+ serNum++;
1519
+ // 设置序号列单元格的值(1、2、3...的格式)
1520
+ sheet.setValue(rowIndex, 1, serNum);
1521
+ }
1522
+ });
1523
+ }
1516
1524
  hasValueRows.forEach((rowIndex, index) => {
1517
1525
  // 设置行可见
1518
1526
  sheet.setRowVisible(rowIndex, true);
@@ -1521,90 +1529,6 @@ const BusinessUtils = {
1521
1529
  // 设置行不可见
1522
1530
  sheet.setRowVisible(rowIndex, false);
1523
1531
  });
1524
- /** 创建空白行单元格 */
1525
- const createBlackRowCell = () => {
1526
- // 工作表总高度
1527
- const sheetTotalHeight = pageDir == 1 ? 1055 : 615;
1528
- // 之前已经创建的空白行索引
1529
- let createBlackRowIndex = -1;
1530
- // 获取所有可见行的总高度
1531
- let allRowHeight = 0;
1532
- for (let i = 0; i < sheet.getRowCount(); i++) {
1533
- const curRowVisible = sheet.getRowVisible(i);
1534
- const blankRowCell = sheet.getTag(i, 1);
1535
- if (curRowVisible && (blankRowCell == null || blankRowCell == undefined || blankRowCell != 'BlankCell')) {
1536
- allRowHeight += sheet.getRowHeight(i);
1537
- }
1538
- // 设置已创建的空白行索引
1539
- if (blankRowCell == 'BlankCell') {
1540
- createBlackRowIndex = i;
1541
- }
1542
- }
1543
- // 针对纵表情况,工作表总高度-表头和表尾总高度>=remainingHeight,空白行不显示;<remainingHeight,空白行显示
1544
- // 是否显示空白行
1545
- let isShowBlankRow = true;
1546
- if (pageDir == 1 && allRowHeight - headerRangeHeight - footerRangeHeight >= remainingHeight) {
1547
- isShowBlankRow = false;
1548
- }
1549
- if (!isShowBlankRow) {
1550
- // 设置行不可见
1551
- if (!isEnable || createBlackRowIndex != -1) {
1552
- sheet.setRowVisible(createBlackRowIndex, false);
1553
- }
1554
- return;
1555
- }
1556
- // 获取到最后一行动态加载区域的行索引
1557
- const lastRowIndex = rowCells[rowCells.length - 1].rowSpan +
1558
- sheet.getSpans({ row: rowCells[rowCells.length - 1].rowSpan, col: 1, rowCount: 1, colCount: 1 })[0].rowCount -
1559
- 1; // dynamicLoadRangeJson[0].row + dynamicLoadRangeJson[0].rowCount - 1;
1560
- // 创建空白行
1561
- if (allRowHeight < sheetTotalHeight) {
1562
- // 获取空白行单元格的标签
1563
- const blankRowCell = sheet.getTag(lastRowIndex + 1, 1);
1564
- if (!blankRowCell || blankRowCell !== 'BlankCell') {
1565
- // 添加一行、合并单元格
1566
- sheet.addRows(lastRowIndex + 1, 1);
1567
- sheet.addSpan(lastRowIndex + 1, 1, 1, 77);
1568
- // 设置添加这一行的行高
1569
- sheet.setRowHeight(lastRowIndex + 1, sheetTotalHeight - allRowHeight);
1570
- // 获取添加这一行的区域范围
1571
- const addRowRange = sheet.getRange(lastRowIndex + 1, 1, 1, 77);
1572
- // 设置边框线
1573
- addRowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.thin), { all: true });
1574
- addRowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.medium), {
1575
- left: true,
1576
- right: true,
1577
- top: false,
1578
- bottom: false,
1579
- });
1580
- // 设置单元格水平和垂直居中
1581
- addRowRange.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
1582
- addRowRange.vAlign(GC.Spread.Sheets.HorizontalAlign.center);
1583
- sheet.setValue(lastRowIndex + 1, 1, blankRowCellValue);
1584
- sheet.setTag(lastRowIndex + 1, 1, 'BlankCell');
1585
- }
1586
- else {
1587
- // 设置添加这一行的行高
1588
- sheet.setRowHeight(lastRowIndex + 1, sheetTotalHeight - allRowHeight);
1589
- if (!isEnable) {
1590
- sheet.setRowVisible(lastRowIndex + 1, false);
1591
- }
1592
- else {
1593
- // 显示空白行单元格
1594
- sheet.setRowVisible(lastRowIndex + 1, true);
1595
- }
1596
- }
1597
- }
1598
- // 隐藏空白行单元格
1599
- else {
1600
- const blankRowCell = sheet.getTag(lastRowIndex + 1, 1);
1601
- // 如果空白行单元格标签存在,则隐藏
1602
- if (!isEnable || (blankRowCell && blankRowCell == 'BlankCell')) {
1603
- sheet.setRowVisible(lastRowIndex + 1, false);
1604
- }
1605
- }
1606
- };
1607
- createBlackRowCell();
1608
1532
  // // 处理单元格边框线的问题
1609
1533
  // const allRowIndex = orderByJson(unionJson(hasValueRows, noValueRows));
1610
1534
  // const rowRange = sheet.getRange(allRowIndex[0], 1, allRowIndex.length, 77);
@@ -1626,124 +1550,6 @@ const BusinessUtils = {
1626
1550
  sheet.setRowVisible(rowIndex, true);
1627
1551
  });
1628
1552
  }
1629
- // 恢复绘制
1630
- sheet.resumePaint();
1631
- // 执行绘制完成后的回调函数
1632
- if (ended != null && ended != undefined && typeof ended === 'function') {
1633
- ended({ hasValueIndex: hasValueRows, noValueIndex: noValueRows });
1634
- }
1635
- return { hasValueIndex: hasValueRows, noValueIndex: noValueRows };
1636
- },
1637
- /**
1638
- * 动态加载行(动态显示数据行和序号值)
1639
- * @param GC GC对象
1640
- * @param spread 工作簿实例
1641
- * @param dynamicLoadRangeJson 动态加载的“试验结果”JSON数组范围,格式如:[{row: 1, col: 1, rowCount: 1, colCount: 1}]
1642
- * @param headerRangeHeight 表头区域总高度
1643
- * @param footerRangeHeight 表尾区域总高度
1644
- * @param remainingHeight 剩余高度(针对纵表情况,工作表总高度-表头和表尾总高度>=remainingHeight,空白行不显示;<remainingHeight,空白行显示)
1645
- * @param pageDir 页面方向(1:纵向、2:横向)
1646
- * @param blankRowCellValue 空白行单元格值,默认为:空白
1647
- * @returns 返回所有需要显示和隐藏的行索引结果对象,格式如:{hasValueIndex: [1, 2, 3], noValueIndex: [4, 5, 6]},hasValueIndex代表所有显示的行索引,noValueIndex代表所有隐藏的行索引
1648
- */
1649
- dynamicLoadRows_Backup: (GC, spread, dynamicLoadRangeJson, headerRangeHeight, footerRangeHeight, remainingHeight = 500, pageDir = 1, blankRowCellValue = '空白') => {
1650
- const sheet = spread.getActiveSheet();
1651
- // 暂停绘制
1652
- sheet.suspendPaint();
1653
- // 获取所有单元格对象
1654
- const cells = SheetUtils.getAllCellObjsByRanges(sheet, dynamicLoadRangeJson);
1655
- // 设置所有行可见,原因是:如果再次执行的时候,第一次隐藏的行没有还原
1656
- cells.forEach((item, index) => {
1657
- sheet.setRowVisible(item.row, true);
1658
- });
1659
- // 获取按照row分组后的数据,格式如:{"1":[{row: 1, col: 43, rowCount: 1, colCount: 24}]}
1660
- const cellsGroupByRow = groupByJson(cells, 'row');
1661
- // 获取序号列的跨列数
1662
- let seqColSpanCount = null;
1663
- // 最终行索引Key对应的单元格对象集合(跨行的索引)
1664
- let rowCells = [];
1665
- forEachJson(cellsGroupByRow, (cellItems, rowIndexKey, source) => {
1666
- if (seqColSpanCount == null) {
1667
- const seqSpans = sheet.getSpans(sheet.getCell(parseInt(rowIndexKey), 1));
1668
- seqColSpanCount = seqSpans[0].colCount;
1669
- }
1670
- // 得到序号列的跨行单元格对象
1671
- const seqColSpanObj = sheet.getSpans({ row: parseInt(rowIndexKey), col: 1, rowCount: cellItems[0].rowCount, colCount: seqColSpanCount })[0];
1672
- // 当前序号跨行单元格对应的所有单元格中是否有值
1673
- let curRowHasValue = false;
1674
- // 当前所有行索引
1675
- let curRowIndexs = [];
1676
- for (let i = 0; i < cellItems.length; i++) {
1677
- // 获取当前单元格对象
1678
- const cell = cellItems[i];
1679
- for (let j = cell.row; j < cell.row + cell.rowCount; j++) {
1680
- if (!curRowIndexs.some((x) => x == j)) {
1681
- curRowIndexs.push(j);
1682
- }
1683
- }
1684
- // 获取当前单元格的值
1685
- const cellValue = sheet.getValue(cell.row, cell.col);
1686
- // 验证是否有值
1687
- if (cellValue !== null &&
1688
- cellValue !== undefined &&
1689
- cellValue !== '' &&
1690
- cellValue !== '/' &&
1691
- !(cellValue instanceof GC.Spread.CalcEngine.CalcError)) {
1692
- curRowHasValue = true;
1693
- break;
1694
- }
1695
- }
1696
- let rowObjs = { row: parseInt(rowIndexKey), rows: curRowIndexs, cells: cellItems, hasValue: curRowHasValue };
1697
- if (!rowCells.some((x) => x.rowSpan == seqColSpanObj.row)) {
1698
- rowCells.push({
1699
- rowSpan: seqColSpanObj.row,
1700
- rows: [rowObjs],
1701
- });
1702
- }
1703
- else {
1704
- let curRow = rowCells.find((x) => x.rowSpan == seqColSpanObj.row);
1705
- curRow.rows.push(rowObjs);
1706
- }
1707
- });
1708
- // 有值和没有值的行索引集合
1709
- let hasValueRows = [], noValueRows = [];
1710
- // 有值的行索引(序号列使用)
1711
- let hasValueRowsSer = [];
1712
- rowCells.forEach((rowObj, index) => {
1713
- if (rowObj.rows.some((x) => x.hasValue) && !hasValueRowsSer.some((x) => x == rowObj.rowSpan)) {
1714
- hasValueRowsSer.push(rowObj.rowSpan);
1715
- }
1716
- if (rowObj.rows.some((x) => x.hasValue)) {
1717
- rowObj.rows.forEach((x) => {
1718
- x.rows.forEach((rowIndex) => {
1719
- if (!hasValueRows.some((hItem) => hItem == rowIndex)) {
1720
- hasValueRows.push(rowIndex);
1721
- }
1722
- });
1723
- });
1724
- }
1725
- else {
1726
- rowObj.rows.forEach((x) => {
1727
- x.rows.forEach((rowIndex) => {
1728
- if (!noValueRows.some((hItem) => hItem == rowIndex)) {
1729
- noValueRows.push(rowIndex);
1730
- }
1731
- });
1732
- });
1733
- }
1734
- });
1735
- hasValueRowsSer.forEach((rowIndex, index) => {
1736
- // 设置序号列单元格的值(1、2、3...的格式)
1737
- sheet.setValue(rowIndex, 1, index + 1);
1738
- });
1739
- hasValueRows.forEach((rowIndex, index) => {
1740
- // 设置行可见
1741
- sheet.setRowVisible(rowIndex, true);
1742
- });
1743
- noValueRows.forEach((rowIndex) => {
1744
- // 设置行不可见
1745
- sheet.setRowVisible(rowIndex, false);
1746
- });
1747
1553
  /** 创建空白行单元格 */
1748
1554
  const createBlackRowCell = () => {
1749
1555
  // 工作表总高度
@@ -1771,13 +1577,15 @@ const BusinessUtils = {
1771
1577
  }
1772
1578
  if (!isShowBlankRow) {
1773
1579
  // 设置行不可见
1774
- if (createBlackRowIndex != -1) {
1580
+ if (!isEnable || createBlackRowIndex != -1) {
1775
1581
  sheet.setRowVisible(createBlackRowIndex, false);
1776
1582
  }
1777
1583
  return;
1778
1584
  }
1779
1585
  // 获取到最后一行动态加载区域的行索引
1780
- const lastRowIndex = dynamicLoadRangeJson[0].row + dynamicLoadRangeJson[0].rowCount - 1;
1586
+ const lastRowIndex = rowCells[rowCells.length - 1].rowSpan +
1587
+ sheet.getSpans({ row: rowCells[rowCells.length - 1].rowSpan, col: 1, rowCount: 1, colCount: 1 })[0].rowCount -
1588
+ 1; // dynamicLoadRangeJson[0].row + dynamicLoadRangeJson[0].rowCount - 1;
1781
1589
  // 创建空白行
1782
1590
  if (allRowHeight < sheetTotalHeight) {
1783
1591
  // 获取空白行单元格的标签
@@ -1807,32 +1615,31 @@ const BusinessUtils = {
1807
1615
  else {
1808
1616
  // 设置添加这一行的行高
1809
1617
  sheet.setRowHeight(lastRowIndex + 1, sheetTotalHeight - allRowHeight);
1810
- // 显示空白行单元格
1811
- sheet.setRowVisible(lastRowIndex + 1, true);
1618
+ if (!isEnable) {
1619
+ sheet.setRowVisible(lastRowIndex + 1, false);
1620
+ }
1621
+ else {
1622
+ // 显示空白行单元格
1623
+ sheet.setRowVisible(lastRowIndex + 1, true);
1624
+ }
1812
1625
  }
1813
1626
  }
1814
1627
  // 隐藏空白行单元格
1815
1628
  else {
1816
1629
  const blankRowCell = sheet.getTag(lastRowIndex + 1, 1);
1817
1630
  // 如果空白行单元格标签存在,则隐藏
1818
- if (blankRowCell && blankRowCell == 'BlankCell') {
1631
+ if (!isEnable || (blankRowCell && blankRowCell == 'BlankCell')) {
1819
1632
  sheet.setRowVisible(lastRowIndex + 1, false);
1820
1633
  }
1821
1634
  }
1822
1635
  };
1823
1636
  createBlackRowCell();
1824
- // // 处理单元格边框线的问题
1825
- // const allRowIndex = orderByJson(unionJson(hasValueRows, noValueRows));
1826
- // const rowRange = sheet.getRange(allRowIndex[0], 1, allRowIndex.length, 77);
1827
- // rowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.thin), { all: true });
1828
- // rowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.medium), {
1829
- // left: true,
1830
- // right: true,
1831
- // top: false,
1832
- // bottom: false,
1833
- // });
1834
1637
  // 恢复绘制
1835
1638
  sheet.resumePaint();
1639
+ // 执行绘制完成后的回调函数
1640
+ if (ended != null && ended != undefined && typeof ended === 'function') {
1641
+ ended({ hasValueIndex: hasValueRows, noValueIndex: noValueRows });
1642
+ }
1836
1643
  return { hasValueIndex: hasValueRows, noValueIndex: noValueRows };
1837
1644
  },
1838
1645
  };