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.cjs.js +38 -231
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +38 -231
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/utils/business.d.ts +0 -16
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1469,7 +1469,7 @@ const BusinessUtils = {
|
|
|
1469
1469
|
}
|
|
1470
1470
|
}
|
|
1471
1471
|
let rowObjs = { row: parseInt(rowIndexKey), rows: curRowIndexs, cells: cellItems, hasValue: curRowHasValue };
|
|
1472
|
-
if (
|
|
1472
|
+
if (!rowCells.some((x) => x.rowSpan == seqColSpanObj.row)) {
|
|
1473
1473
|
let rowIndexs = [];
|
|
1474
1474
|
const seqColSpanRowSpan = sheet.getSpans({ row: seqColSpanObj.row, col: 1, rowCount: 1, colCount: 1 })[0];
|
|
1475
1475
|
for (let i = 0; i < seqColSpanRowSpan.rowCount; i++) {
|
|
@@ -1482,10 +1482,8 @@ const BusinessUtils = {
|
|
|
1482
1482
|
});
|
|
1483
1483
|
}
|
|
1484
1484
|
else {
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
curRow.rows.push(rowObjs);
|
|
1488
|
-
}
|
|
1485
|
+
let curRow = rowCells.find((x) => x.rowSpan == seqColSpanObj.row);
|
|
1486
|
+
curRow.rows.push(rowObjs);
|
|
1489
1487
|
}
|
|
1490
1488
|
});
|
|
1491
1489
|
// 有值和没有值的行索引集合
|
|
@@ -1525,16 +1523,26 @@ const BusinessUtils = {
|
|
|
1525
1523
|
});
|
|
1526
1524
|
}
|
|
1527
1525
|
});
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
// 检查第一个单元格的值是否包含非数字字符,有非数字字符的时候代表不填充序号
|
|
1532
|
-
if (!/^(?!\d+$)[\u4e00-\u9fa5a-zA-Z0-9!@#$%^&*()_+[\]{};':",.\/?\\|-]+$/.test(curVal)) {
|
|
1533
|
-
serNum++;
|
|
1526
|
+
// 禁用的时候,将所有的序号重新设置
|
|
1527
|
+
if (!isEnable) {
|
|
1528
|
+
rowCells.forEach((rowObj, index) => {
|
|
1534
1529
|
// 设置序号列单元格的值(1、2、3...的格式)
|
|
1535
|
-
sheet.setValue(
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1530
|
+
sheet.setValue(rowObj.rowSpan, 1, index + 1);
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
// 启用的时候
|
|
1534
|
+
else {
|
|
1535
|
+
let serNum = 0;
|
|
1536
|
+
hasValueRowsSer.forEach((rowIndex, index) => {
|
|
1537
|
+
const curVal = sheet.getValue(rowIndex, 1);
|
|
1538
|
+
// 检查第一个单元格的值是否包含非数字字符,有非数字字符的时候代表不填充序号
|
|
1539
|
+
if (!/^(?!\d+$)[\u4e00-\u9fa5a-zA-Z0-9!@#$%^&*()_+[\]{};':",.\/?\\|-]+$/.test(curVal)) {
|
|
1540
|
+
serNum++;
|
|
1541
|
+
// 设置序号列单元格的值(1、2、3...的格式)
|
|
1542
|
+
sheet.setValue(rowIndex, 1, serNum);
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1538
1546
|
hasValueRows.forEach((rowIndex, index) => {
|
|
1539
1547
|
// 设置行可见
|
|
1540
1548
|
sheet.setRowVisible(rowIndex, true);
|
|
@@ -1543,90 +1551,6 @@ const BusinessUtils = {
|
|
|
1543
1551
|
// 设置行不可见
|
|
1544
1552
|
sheet.setRowVisible(rowIndex, false);
|
|
1545
1553
|
});
|
|
1546
|
-
/** 创建空白行单元格 */
|
|
1547
|
-
const createBlackRowCell = () => {
|
|
1548
|
-
// 工作表总高度
|
|
1549
|
-
const sheetTotalHeight = pageDir == 1 ? 1055 : 615;
|
|
1550
|
-
// 之前已经创建的空白行索引
|
|
1551
|
-
let createBlackRowIndex = -1;
|
|
1552
|
-
// 获取所有可见行的总高度
|
|
1553
|
-
let allRowHeight = 0;
|
|
1554
|
-
for (let i = 0; i < sheet.getRowCount(); i++) {
|
|
1555
|
-
const curRowVisible = sheet.getRowVisible(i);
|
|
1556
|
-
const blankRowCell = sheet.getTag(i, 1);
|
|
1557
|
-
if (curRowVisible && (blankRowCell == null || blankRowCell == undefined || blankRowCell != 'BlankCell')) {
|
|
1558
|
-
allRowHeight += sheet.getRowHeight(i);
|
|
1559
|
-
}
|
|
1560
|
-
// 设置已创建的空白行索引
|
|
1561
|
-
if (blankRowCell == 'BlankCell') {
|
|
1562
|
-
createBlackRowIndex = i;
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
// 针对纵表情况,工作表总高度-表头和表尾总高度>=remainingHeight,空白行不显示;<remainingHeight,空白行显示
|
|
1566
|
-
// 是否显示空白行
|
|
1567
|
-
let isShowBlankRow = true;
|
|
1568
|
-
if (pageDir == 1 && allRowHeight - headerRangeHeight - footerRangeHeight >= remainingHeight) {
|
|
1569
|
-
isShowBlankRow = false;
|
|
1570
|
-
}
|
|
1571
|
-
if (!isShowBlankRow) {
|
|
1572
|
-
// 设置行不可见
|
|
1573
|
-
if (!isEnable || createBlackRowIndex != -1) {
|
|
1574
|
-
sheet.setRowVisible(createBlackRowIndex, false);
|
|
1575
|
-
}
|
|
1576
|
-
return;
|
|
1577
|
-
}
|
|
1578
|
-
// 获取到最后一行动态加载区域的行索引
|
|
1579
|
-
const lastRowIndex = rowCells[rowCells.length - 1].rowSpan +
|
|
1580
|
-
sheet.getSpans({ row: rowCells[rowCells.length - 1].rowSpan, col: 1, rowCount: 1, colCount: 1 })[0].rowCount -
|
|
1581
|
-
1; // dynamicLoadRangeJson[0].row + dynamicLoadRangeJson[0].rowCount - 1;
|
|
1582
|
-
// 创建空白行
|
|
1583
|
-
if (allRowHeight < sheetTotalHeight) {
|
|
1584
|
-
// 获取空白行单元格的标签
|
|
1585
|
-
const blankRowCell = sheet.getTag(lastRowIndex + 1, 1);
|
|
1586
|
-
if (!blankRowCell || blankRowCell !== 'BlankCell') {
|
|
1587
|
-
// 添加一行、合并单元格
|
|
1588
|
-
sheet.addRows(lastRowIndex + 1, 1);
|
|
1589
|
-
sheet.addSpan(lastRowIndex + 1, 1, 1, 77);
|
|
1590
|
-
// 设置添加这一行的行高
|
|
1591
|
-
sheet.setRowHeight(lastRowIndex + 1, sheetTotalHeight - allRowHeight);
|
|
1592
|
-
// 获取添加这一行的区域范围
|
|
1593
|
-
const addRowRange = sheet.getRange(lastRowIndex + 1, 1, 1, 77);
|
|
1594
|
-
// 设置边框线
|
|
1595
|
-
addRowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.thin), { all: true });
|
|
1596
|
-
addRowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.medium), {
|
|
1597
|
-
left: true,
|
|
1598
|
-
right: true,
|
|
1599
|
-
top: false,
|
|
1600
|
-
bottom: false,
|
|
1601
|
-
});
|
|
1602
|
-
// 设置单元格水平和垂直居中
|
|
1603
|
-
addRowRange.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
|
|
1604
|
-
addRowRange.vAlign(GC.Spread.Sheets.HorizontalAlign.center);
|
|
1605
|
-
sheet.setValue(lastRowIndex + 1, 1, blankRowCellValue);
|
|
1606
|
-
sheet.setTag(lastRowIndex + 1, 1, 'BlankCell');
|
|
1607
|
-
}
|
|
1608
|
-
else {
|
|
1609
|
-
// 设置添加这一行的行高
|
|
1610
|
-
sheet.setRowHeight(lastRowIndex + 1, sheetTotalHeight - allRowHeight);
|
|
1611
|
-
if (!isEnable) {
|
|
1612
|
-
sheet.setRowVisible(lastRowIndex + 1, false);
|
|
1613
|
-
}
|
|
1614
|
-
else {
|
|
1615
|
-
// 显示空白行单元格
|
|
1616
|
-
sheet.setRowVisible(lastRowIndex + 1, true);
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
// 隐藏空白行单元格
|
|
1621
|
-
else {
|
|
1622
|
-
const blankRowCell = sheet.getTag(lastRowIndex + 1, 1);
|
|
1623
|
-
// 如果空白行单元格标签存在,则隐藏
|
|
1624
|
-
if (!isEnable || (blankRowCell && blankRowCell == 'BlankCell')) {
|
|
1625
|
-
sheet.setRowVisible(lastRowIndex + 1, false);
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
};
|
|
1629
|
-
createBlackRowCell();
|
|
1630
1554
|
// // 处理单元格边框线的问题
|
|
1631
1555
|
// const allRowIndex = orderByJson(unionJson(hasValueRows, noValueRows));
|
|
1632
1556
|
// const rowRange = sheet.getRange(allRowIndex[0], 1, allRowIndex.length, 77);
|
|
@@ -1648,124 +1572,6 @@ const BusinessUtils = {
|
|
|
1648
1572
|
sheet.setRowVisible(rowIndex, true);
|
|
1649
1573
|
});
|
|
1650
1574
|
}
|
|
1651
|
-
// 恢复绘制
|
|
1652
|
-
sheet.resumePaint();
|
|
1653
|
-
// 执行绘制完成后的回调函数
|
|
1654
|
-
if (ended != null && ended != undefined && typeof ended === 'function') {
|
|
1655
|
-
ended({ hasValueIndex: hasValueRows, noValueIndex: noValueRows });
|
|
1656
|
-
}
|
|
1657
|
-
return { hasValueIndex: hasValueRows, noValueIndex: noValueRows };
|
|
1658
|
-
},
|
|
1659
|
-
/**
|
|
1660
|
-
* 动态加载行(动态显示数据行和序号值)
|
|
1661
|
-
* @param GC GC对象
|
|
1662
|
-
* @param spread 工作簿实例
|
|
1663
|
-
* @param dynamicLoadRangeJson 动态加载的“试验结果”JSON数组范围,格式如:[{row: 1, col: 1, rowCount: 1, colCount: 1}]
|
|
1664
|
-
* @param headerRangeHeight 表头区域总高度
|
|
1665
|
-
* @param footerRangeHeight 表尾区域总高度
|
|
1666
|
-
* @param remainingHeight 剩余高度(针对纵表情况,工作表总高度-表头和表尾总高度>=remainingHeight,空白行不显示;<remainingHeight,空白行显示)
|
|
1667
|
-
* @param pageDir 页面方向(1:纵向、2:横向)
|
|
1668
|
-
* @param blankRowCellValue 空白行单元格值,默认为:空白
|
|
1669
|
-
* @returns 返回所有需要显示和隐藏的行索引结果对象,格式如:{hasValueIndex: [1, 2, 3], noValueIndex: [4, 5, 6]},hasValueIndex代表所有显示的行索引,noValueIndex代表所有隐藏的行索引
|
|
1670
|
-
*/
|
|
1671
|
-
dynamicLoadRows_Backup: (GC, spread, dynamicLoadRangeJson, headerRangeHeight, footerRangeHeight, remainingHeight = 500, pageDir = 1, blankRowCellValue = '空白') => {
|
|
1672
|
-
const sheet = spread.getActiveSheet();
|
|
1673
|
-
// 暂停绘制
|
|
1674
|
-
sheet.suspendPaint();
|
|
1675
|
-
// 获取所有单元格对象
|
|
1676
|
-
const cells = SheetUtils.getAllCellObjsByRanges(sheet, dynamicLoadRangeJson);
|
|
1677
|
-
// 设置所有行可见,原因是:如果再次执行的时候,第一次隐藏的行没有还原
|
|
1678
|
-
cells.forEach((item, index) => {
|
|
1679
|
-
sheet.setRowVisible(item.row, true);
|
|
1680
|
-
});
|
|
1681
|
-
// 获取按照row分组后的数据,格式如:{"1":[{row: 1, col: 43, rowCount: 1, colCount: 24}]}
|
|
1682
|
-
const cellsGroupByRow = rapidUtils.groupByJson(cells, 'row');
|
|
1683
|
-
// 获取序号列的跨列数
|
|
1684
|
-
let seqColSpanCount = null;
|
|
1685
|
-
// 最终行索引Key对应的单元格对象集合(跨行的索引)
|
|
1686
|
-
let rowCells = [];
|
|
1687
|
-
rapidUtils.forEachJson(cellsGroupByRow, (cellItems, rowIndexKey, source) => {
|
|
1688
|
-
if (seqColSpanCount == null) {
|
|
1689
|
-
const seqSpans = sheet.getSpans(sheet.getCell(parseInt(rowIndexKey), 1));
|
|
1690
|
-
seqColSpanCount = seqSpans[0].colCount;
|
|
1691
|
-
}
|
|
1692
|
-
// 得到序号列的跨行单元格对象
|
|
1693
|
-
const seqColSpanObj = sheet.getSpans({ row: parseInt(rowIndexKey), col: 1, rowCount: cellItems[0].rowCount, colCount: seqColSpanCount })[0];
|
|
1694
|
-
// 当前序号跨行单元格对应的所有单元格中是否有值
|
|
1695
|
-
let curRowHasValue = false;
|
|
1696
|
-
// 当前所有行索引
|
|
1697
|
-
let curRowIndexs = [];
|
|
1698
|
-
for (let i = 0; i < cellItems.length; i++) {
|
|
1699
|
-
// 获取当前单元格对象
|
|
1700
|
-
const cell = cellItems[i];
|
|
1701
|
-
for (let j = cell.row; j < cell.row + cell.rowCount; j++) {
|
|
1702
|
-
if (!curRowIndexs.some((x) => x == j)) {
|
|
1703
|
-
curRowIndexs.push(j);
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
// 获取当前单元格的值
|
|
1707
|
-
const cellValue = sheet.getValue(cell.row, cell.col);
|
|
1708
|
-
// 验证是否有值
|
|
1709
|
-
if (cellValue !== null &&
|
|
1710
|
-
cellValue !== undefined &&
|
|
1711
|
-
cellValue !== '' &&
|
|
1712
|
-
cellValue !== '/' &&
|
|
1713
|
-
!(cellValue instanceof GC.Spread.CalcEngine.CalcError)) {
|
|
1714
|
-
curRowHasValue = true;
|
|
1715
|
-
break;
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
let rowObjs = { row: parseInt(rowIndexKey), rows: curRowIndexs, cells: cellItems, hasValue: curRowHasValue };
|
|
1719
|
-
if (!rowCells.some((x) => x.rowSpan == seqColSpanObj.row)) {
|
|
1720
|
-
rowCells.push({
|
|
1721
|
-
rowSpan: seqColSpanObj.row,
|
|
1722
|
-
rows: [rowObjs],
|
|
1723
|
-
});
|
|
1724
|
-
}
|
|
1725
|
-
else {
|
|
1726
|
-
let curRow = rowCells.find((x) => x.rowSpan == seqColSpanObj.row);
|
|
1727
|
-
curRow.rows.push(rowObjs);
|
|
1728
|
-
}
|
|
1729
|
-
});
|
|
1730
|
-
// 有值和没有值的行索引集合
|
|
1731
|
-
let hasValueRows = [], noValueRows = [];
|
|
1732
|
-
// 有值的行索引(序号列使用)
|
|
1733
|
-
let hasValueRowsSer = [];
|
|
1734
|
-
rowCells.forEach((rowObj, index) => {
|
|
1735
|
-
if (rowObj.rows.some((x) => x.hasValue) && !hasValueRowsSer.some((x) => x == rowObj.rowSpan)) {
|
|
1736
|
-
hasValueRowsSer.push(rowObj.rowSpan);
|
|
1737
|
-
}
|
|
1738
|
-
if (rowObj.rows.some((x) => x.hasValue)) {
|
|
1739
|
-
rowObj.rows.forEach((x) => {
|
|
1740
|
-
x.rows.forEach((rowIndex) => {
|
|
1741
|
-
if (!hasValueRows.some((hItem) => hItem == rowIndex)) {
|
|
1742
|
-
hasValueRows.push(rowIndex);
|
|
1743
|
-
}
|
|
1744
|
-
});
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
|
-
else {
|
|
1748
|
-
rowObj.rows.forEach((x) => {
|
|
1749
|
-
x.rows.forEach((rowIndex) => {
|
|
1750
|
-
if (!noValueRows.some((hItem) => hItem == rowIndex)) {
|
|
1751
|
-
noValueRows.push(rowIndex);
|
|
1752
|
-
}
|
|
1753
|
-
});
|
|
1754
|
-
});
|
|
1755
|
-
}
|
|
1756
|
-
});
|
|
1757
|
-
hasValueRowsSer.forEach((rowIndex, index) => {
|
|
1758
|
-
// 设置序号列单元格的值(1、2、3...的格式)
|
|
1759
|
-
sheet.setValue(rowIndex, 1, index + 1);
|
|
1760
|
-
});
|
|
1761
|
-
hasValueRows.forEach((rowIndex, index) => {
|
|
1762
|
-
// 设置行可见
|
|
1763
|
-
sheet.setRowVisible(rowIndex, true);
|
|
1764
|
-
});
|
|
1765
|
-
noValueRows.forEach((rowIndex) => {
|
|
1766
|
-
// 设置行不可见
|
|
1767
|
-
sheet.setRowVisible(rowIndex, false);
|
|
1768
|
-
});
|
|
1769
1575
|
/** 创建空白行单元格 */
|
|
1770
1576
|
const createBlackRowCell = () => {
|
|
1771
1577
|
// 工作表总高度
|
|
@@ -1793,13 +1599,15 @@ const BusinessUtils = {
|
|
|
1793
1599
|
}
|
|
1794
1600
|
if (!isShowBlankRow) {
|
|
1795
1601
|
// 设置行不可见
|
|
1796
|
-
if (createBlackRowIndex != -1) {
|
|
1602
|
+
if (!isEnable || createBlackRowIndex != -1) {
|
|
1797
1603
|
sheet.setRowVisible(createBlackRowIndex, false);
|
|
1798
1604
|
}
|
|
1799
1605
|
return;
|
|
1800
1606
|
}
|
|
1801
1607
|
// 获取到最后一行动态加载区域的行索引
|
|
1802
|
-
const lastRowIndex =
|
|
1608
|
+
const lastRowIndex = rowCells[rowCells.length - 1].rowSpan +
|
|
1609
|
+
sheet.getSpans({ row: rowCells[rowCells.length - 1].rowSpan, col: 1, rowCount: 1, colCount: 1 })[0].rowCount -
|
|
1610
|
+
1; // dynamicLoadRangeJson[0].row + dynamicLoadRangeJson[0].rowCount - 1;
|
|
1803
1611
|
// 创建空白行
|
|
1804
1612
|
if (allRowHeight < sheetTotalHeight) {
|
|
1805
1613
|
// 获取空白行单元格的标签
|
|
@@ -1829,32 +1637,31 @@ const BusinessUtils = {
|
|
|
1829
1637
|
else {
|
|
1830
1638
|
// 设置添加这一行的行高
|
|
1831
1639
|
sheet.setRowHeight(lastRowIndex + 1, sheetTotalHeight - allRowHeight);
|
|
1832
|
-
|
|
1833
|
-
|
|
1640
|
+
if (!isEnable) {
|
|
1641
|
+
sheet.setRowVisible(lastRowIndex + 1, false);
|
|
1642
|
+
}
|
|
1643
|
+
else {
|
|
1644
|
+
// 显示空白行单元格
|
|
1645
|
+
sheet.setRowVisible(lastRowIndex + 1, true);
|
|
1646
|
+
}
|
|
1834
1647
|
}
|
|
1835
1648
|
}
|
|
1836
1649
|
// 隐藏空白行单元格
|
|
1837
1650
|
else {
|
|
1838
1651
|
const blankRowCell = sheet.getTag(lastRowIndex + 1, 1);
|
|
1839
1652
|
// 如果空白行单元格标签存在,则隐藏
|
|
1840
|
-
if (blankRowCell && blankRowCell == 'BlankCell') {
|
|
1653
|
+
if (!isEnable || (blankRowCell && blankRowCell == 'BlankCell')) {
|
|
1841
1654
|
sheet.setRowVisible(lastRowIndex + 1, false);
|
|
1842
1655
|
}
|
|
1843
1656
|
}
|
|
1844
1657
|
};
|
|
1845
1658
|
createBlackRowCell();
|
|
1846
|
-
// // 处理单元格边框线的问题
|
|
1847
|
-
// const allRowIndex = orderByJson(unionJson(hasValueRows, noValueRows));
|
|
1848
|
-
// const rowRange = sheet.getRange(allRowIndex[0], 1, allRowIndex.length, 77);
|
|
1849
|
-
// rowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.thin), { all: true });
|
|
1850
|
-
// rowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.medium), {
|
|
1851
|
-
// left: true,
|
|
1852
|
-
// right: true,
|
|
1853
|
-
// top: false,
|
|
1854
|
-
// bottom: false,
|
|
1855
|
-
// });
|
|
1856
1659
|
// 恢复绘制
|
|
1857
1660
|
sheet.resumePaint();
|
|
1661
|
+
// 执行绘制完成后的回调函数
|
|
1662
|
+
if (ended != null && ended != undefined && typeof ended === 'function') {
|
|
1663
|
+
ended({ hasValueIndex: hasValueRows, noValueIndex: noValueRows });
|
|
1664
|
+
}
|
|
1858
1665
|
return { hasValueIndex: hasValueRows, noValueIndex: noValueRows };
|
|
1859
1666
|
},
|
|
1860
1667
|
};
|