rapid-spreadjs 1.0.131 → 1.0.132

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
@@ -1359,9 +1359,11 @@ const BusinessUtils = {
1359
1359
  * @param GC GC对象
1360
1360
  * @param spread 工作簿实例
1361
1361
  * @param dynamicLoadRangeJson 动态加载的“试验结果”JSON数组范围,格式如:[{row: 1, col: 1, rowCount: 1, colCount: 1}]
1362
+ * @param pageDir 页面方向(1:纵向、2:横向)
1363
+ * @param blankRowCellValue 空白行单元格值,默认为:空白
1362
1364
  * @returns 返回所有需要显示和隐藏的行索引结果对象,格式如:{hasValueIndex: [1, 2, 3], noValueIndex: [4, 5, 6]},hasValueIndex代表所有显示的行索引,noValueIndex代表所有隐藏的行索引
1363
1365
  */
1364
- dynamicLoadRows: (GC, spread, dynamicLoadRangeJson) => {
1366
+ dynamicLoadRows: (GC, spread, dynamicLoadRangeJson, pageDir = 1, blankRowCellValue = '空白') => {
1365
1367
  const sheet = spread.getActiveSheet();
1366
1368
  // 暂停绘制
1367
1369
  sheet.suspendPaint();
@@ -1416,16 +1418,16 @@ const BusinessUtils = {
1416
1418
  // 有值和没有值的行索引集合
1417
1419
  let hasValueRows = [], noValueRows = [];
1418
1420
  rowCells.forEach((rowObj, index) => {
1419
- if (rowObj.rows.some((x) => x.hasValue)) {
1421
+ if (rowObj.rows.some((x) => x.hasValue) && !hasValueRows.some((x) => x == rowObj.rowSpan)) {
1420
1422
  hasValueRows.push(rowObj.rowSpan);
1421
1423
  }
1422
1424
  else {
1423
1425
  rowObj.rows.forEach((x) => {
1424
1426
  x.cells.forEach((cell) => {
1425
- noValueRows.push(cell.row);
1427
+ if (!noValueRows.some((x) => x == cell.row))
1428
+ noValueRows.push(cell.row);
1426
1429
  });
1427
1430
  });
1428
- noValueRows.push(rowObj.rowSpan);
1429
1431
  }
1430
1432
  });
1431
1433
  hasValueRows.forEach((rowIndex, index) => {
@@ -1438,8 +1440,74 @@ const BusinessUtils = {
1438
1440
  // 设置行不可见
1439
1441
  sheet.setRowVisible(rowIndex, false);
1440
1442
  });
1443
+ /** 创建空白行单元格 */
1444
+ const createBlackRowCell = () => {
1445
+ // 工作表总高度
1446
+ const sheetTotalHeight = pageDir ? 1055 : 615;
1447
+ // 获取所有可见行的总高度
1448
+ let allRowHeight = 0;
1449
+ for (let i = 0; i < sheet.getRowCount(); i++) {
1450
+ const curRowVisible = sheet.getRowVisible(i);
1451
+ const blankRowCell = sheet.getTag(i, 1);
1452
+ if (curRowVisible && (blankRowCell == null || blankRowCell == undefined || blankRowCell != 'BlankCell')) {
1453
+ allRowHeight += sheet.getRowHeight(i);
1454
+ }
1455
+ }
1456
+ // 获取到最后一行动态加载区域的行索引
1457
+ const lastRowIndex = rowCells[rowCells.length - 1].rows[rowCells[rowCells.length - 1].rows.length - 1].row;
1458
+ // 创建空白行
1459
+ if (allRowHeight < sheetTotalHeight) {
1460
+ // 获取空白行单元格的标签
1461
+ const blankRowCell = sheet.getTag(lastRowIndex + 1, 1);
1462
+ if (!blankRowCell || blankRowCell !== 'BlankCell') {
1463
+ // 添加一行、合并单元格
1464
+ sheet.addRows(lastRowIndex + 1, 1);
1465
+ sheet.addSpan(lastRowIndex + 1, 1, 1, 77);
1466
+ // 设置添加这一行的行高
1467
+ sheet.setRowHeight(lastRowIndex + 1, sheetTotalHeight - allRowHeight);
1468
+ // 获取添加这一行的区域范围
1469
+ const addRowRange = sheet.getRange(lastRowIndex + 1, 1, 1, 77);
1470
+ // 设置边框线
1471
+ addRowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.thin), { all: true });
1472
+ addRowRange.setBorder(new GC.Spread.Sheets.LineBorder('#000', GC.Spread.Sheets.LineStyle.medium), {
1473
+ left: true,
1474
+ right: true,
1475
+ top: false,
1476
+ bottom: false,
1477
+ });
1478
+ // 设置单元格水平和垂直居中
1479
+ addRowRange.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
1480
+ addRowRange.vAlign(GC.Spread.Sheets.HorizontalAlign.center);
1481
+ sheet.setValue(lastRowIndex + 1, 1, blankRowCellValue);
1482
+ sheet.setTag(lastRowIndex + 1, 1, 'BlankCell');
1483
+ }
1484
+ else {
1485
+ // 设置添加这一行的行高
1486
+ sheet.setRowHeight(lastRowIndex + 1, sheetTotalHeight - allRowHeight);
1487
+ // 显示空白行单元格
1488
+ sheet.setRowVisible(lastRowIndex + 1, true);
1489
+ }
1490
+ }
1491
+ // 隐藏空白行单元格
1492
+ else {
1493
+ const blankRowCell = sheet.getTag(lastRowIndex + 1, 1);
1494
+ // 如果空白行单元格标签存在,则隐藏
1495
+ if (blankRowCell && blankRowCell == 'BlankCell') {
1496
+ sheet.setRowVisible(lastRowIndex + 1, false);
1497
+ }
1498
+ }
1499
+ };
1500
+ createBlackRowCell();
1441
1501
  // 恢复绘制
1442
1502
  sheet.resumePaint();
1503
+ let allRowHeight = 0;
1504
+ for (let i = 0; i < sheet.getRowCount(); i++) {
1505
+ const curRowVisible = sheet.getRowVisible(i);
1506
+ if (curRowVisible) {
1507
+ allRowHeight += sheet.getRowHeight(i);
1508
+ }
1509
+ }
1510
+ console.log('创建空白行单元格后的总高度:', allRowHeight);
1443
1511
  return { hasValueIndex: hasValueRows, noValueIndex: noValueRows };
1444
1512
  },
1445
1513
  };