rapid-spreadjs 1.0.50 → 1.0.52
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 +86 -9
- 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 +87 -10
- 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 +20 -3
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -684,12 +684,13 @@ const BusinessUtils = {
|
|
|
684
684
|
* @param gc GC对象
|
|
685
685
|
* @param sheet 工作表实例
|
|
686
686
|
* @param testObjectAttrs 检测对象属性配置集合
|
|
687
|
+
* @param addRowIndex 添加检测对象属性区域的起始行索引,默认为:0
|
|
687
688
|
* @param isVertical 是否为纵表,默认为:true
|
|
688
689
|
* @param contentColStartIndex 表格内容列起始索引,默认为:1
|
|
689
690
|
* @param contentTotalColCount 表格内容列总数,默认为:77
|
|
690
|
-
* @param addRowHeight 添加的表格行高,默认为:24
|
|
691
|
+
* @param addRowHeight 添加的表格行高,默认为:24(单位为像素)
|
|
691
692
|
*/
|
|
692
|
-
createTestObjectAttrsCells: (gc, sheet, testObjectAttrs, isVertical = true, contentColStartIndex = 1, contentTotalColCount = 77, addRowHeight = 24) => {
|
|
693
|
+
createTestObjectAttrsCells: (gc, sheet, testObjectAttrs, addRowIndex = 0, isVertical = true, contentColStartIndex = 1, contentTotalColCount = 77, addRowHeight = 24) => {
|
|
693
694
|
if (!testObjectAttrs || testObjectAttrs.length === 0) {
|
|
694
695
|
return;
|
|
695
696
|
}
|
|
@@ -703,8 +704,14 @@ const BusinessUtils = {
|
|
|
703
704
|
const testObjectAttrsChunk = rapidUtils.chunkJson(testObjectAttrs, rowTestObjectCount);
|
|
704
705
|
// 暂停绘制
|
|
705
706
|
sheet.suspendPaint();
|
|
706
|
-
// 设置工作表行数为0
|
|
707
|
-
sheet.setRowCount(0);
|
|
707
|
+
// // 设置工作表行数为0
|
|
708
|
+
// sheet.setRowCount(0);
|
|
709
|
+
// 获取当前Sheet的行数
|
|
710
|
+
const rowCount = sheet.getRowCount();
|
|
711
|
+
// 如果满足如下条件,则将末尾的行全部删除
|
|
712
|
+
if (addRowIndex > 0 && addRowIndex < rowCount) {
|
|
713
|
+
sheet.deleteRows(addRowIndex, rowCount - addRowIndex);
|
|
714
|
+
}
|
|
708
715
|
/**
|
|
709
716
|
* 设置单元格字体和大小
|
|
710
717
|
* @param row
|
|
@@ -772,11 +779,12 @@ const BusinessUtils = {
|
|
|
772
779
|
* 获取检测对象属性值集合
|
|
773
780
|
* @param sheet 工作表实例
|
|
774
781
|
* @param testObjectAttrs 检测对象属性配置集合
|
|
782
|
+
* @param addRowIndex 添加检测对象属性区域的起始行索引,默认为:0
|
|
775
783
|
* @param isVertical 是否为纵表,默认为:true
|
|
776
784
|
* @param contentColStartIndex 表格内容列起始索引,默认为:1
|
|
777
785
|
* @param contentTotalColCount 表格内容列总数,默认为:77
|
|
778
786
|
*/
|
|
779
|
-
getTestObjectAttrsVals: (sheet, testObjectAttrs, isVertical = true, contentColStartIndex = 1, contentTotalColCount = 77) => {
|
|
787
|
+
getTestObjectAttrsVals: (sheet, testObjectAttrs, addRowIndex = 0, isVertical = true, contentColStartIndex = 1, contentTotalColCount = 77) => {
|
|
780
788
|
// 一行中检测对象属性的个数(纵表为2个,横表为3个)
|
|
781
789
|
const rowTestObjectCount = isVertical ? 2 : 3;
|
|
782
790
|
// 将测试对象属性数据进行分块
|
|
@@ -785,7 +793,7 @@ const BusinessUtils = {
|
|
|
785
793
|
sheet.suspendPaint();
|
|
786
794
|
// 所有单元格对象
|
|
787
795
|
const allCells = SheetUtils.getAllCellObjsByRange(sheet, {
|
|
788
|
-
row:
|
|
796
|
+
row: addRowIndex,
|
|
789
797
|
col: contentColStartIndex,
|
|
790
798
|
rowCount: sheet.getRowCount(),
|
|
791
799
|
colCount: contentTotalColCount,
|
|
@@ -813,6 +821,75 @@ const BusinessUtils = {
|
|
|
813
821
|
sheet.resumePaint();
|
|
814
822
|
return retData;
|
|
815
823
|
},
|
|
824
|
+
/**
|
|
825
|
+
* 动态创建循环行
|
|
826
|
+
* @param GC GC对象
|
|
827
|
+
* @param spread 工作簿实例
|
|
828
|
+
* @param cellRange 单元格范围JSON对象,格式为:{row:0, col:0, rowCount:2, colCount:5}
|
|
829
|
+
* @param curDefaultPointCount 本次默认点数
|
|
830
|
+
* @param lastDefaultPointCount 上次默认点数,默认为:0(0代表首次创建)
|
|
831
|
+
* @param rowHeight 创建的行高度,默认为:24(单位为像素)
|
|
832
|
+
*/
|
|
833
|
+
dynamicCreateCyclicRows: (GC, spread, cellRange, curDefaultPointCount, lastDefaultPointCount = 0, rowHeight = 24) => {
|
|
834
|
+
// 不进行动态创建行
|
|
835
|
+
if ((curDefaultPointCount <= 1 && lastDefaultPointCount == 0) || (curDefaultPointCount == lastDefaultPointCount && lastDefaultPointCount > 0)) {
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
// 获取当前工作表
|
|
839
|
+
const sheet = spread.getActiveSheet();
|
|
840
|
+
/**
|
|
841
|
+
* 添加行
|
|
842
|
+
* @param addRowIndex 添加行的索引位置
|
|
843
|
+
* @param addRowCount 添加行的数量
|
|
844
|
+
* @param copyPointCount 复制点数的数量
|
|
845
|
+
* @param targetRowIndex 循环复制的时候,需要加上的行索引,默认为0
|
|
846
|
+
*/
|
|
847
|
+
const addRowsFun = (addRowIndex, addRowCount, copyPointCount, targetRowIndex = 0) => {
|
|
848
|
+
// 添加需要循环的总行数
|
|
849
|
+
sheet.addRows(addRowIndex, addRowCount);
|
|
850
|
+
// 设置添加行的行高
|
|
851
|
+
for (let i = addRowIndex; i <= addRowIndex + addRowCount; i++) {
|
|
852
|
+
sheet.setRowHeight(i, rowHeight, GC.Spread.Sheets.SheetArea.viewport);
|
|
853
|
+
}
|
|
854
|
+
// 复制次数,每次复制到下方相邻位置
|
|
855
|
+
for (let i = 1; i <= copyPointCount; i++) {
|
|
856
|
+
// 计算目标起始行
|
|
857
|
+
const targetRow = cellRange.row + targetRowIndex + i * cellRange.rowCount;
|
|
858
|
+
// 使用sheet.copyTo方法进行复制
|
|
859
|
+
sheet.copyTo(cellRange.row, // 源起始行
|
|
860
|
+
cellRange.col, // 源起始列
|
|
861
|
+
targetRow, // 目标起始行
|
|
862
|
+
cellRange.col, // 目标起始列
|
|
863
|
+
cellRange.rowCount, // 源行数
|
|
864
|
+
cellRange.colCount, // 源列数
|
|
865
|
+
GC.Spread.Sheets.CopyToOptions.all // 复制内容类型(值、样式、公式等)
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
// 暂停绘制
|
|
870
|
+
sheet.suspendPaint();
|
|
871
|
+
// 当前默认点数<=1并且上一次默认点数>0的时候,则删除所有循环的行
|
|
872
|
+
if (curDefaultPointCount <= 1 && lastDefaultPointCount > 0) {
|
|
873
|
+
sheet.deleteRows(cellRange.row + cellRange.rowCount, (curDefaultPointCount - 1) * cellRange.rowCount);
|
|
874
|
+
}
|
|
875
|
+
// 当前默认点数>1并且上次默认点数>1的时候
|
|
876
|
+
else if (curDefaultPointCount > 1 && lastDefaultPointCount > 1) {
|
|
877
|
+
// 当前默认点数>上次默认点数时,则需要增加curDefaultPointCount-lastDefaultPointCount次循环
|
|
878
|
+
if (curDefaultPointCount > lastDefaultPointCount) {
|
|
879
|
+
addRowsFun(cellRange.row + cellRange.rowCount + (curDefaultPointCount - lastDefaultPointCount - 1) * cellRange.rowCount, (curDefaultPointCount - lastDefaultPointCount) * cellRange.rowCount, curDefaultPointCount - lastDefaultPointCount, (curDefaultPointCount - lastDefaultPointCount - 1) * cellRange.rowCount);
|
|
880
|
+
}
|
|
881
|
+
// 当前默认点数<上次默认点数时,则需要删除lastDefaultPointCount-curDefaultPointCount次循环所在的行
|
|
882
|
+
else if (curDefaultPointCount < lastDefaultPointCount) {
|
|
883
|
+
sheet.deleteRows(cellRange.row + cellRange.rowCount + (curDefaultPointCount - 1) * cellRange.rowCount, (lastDefaultPointCount - curDefaultPointCount) * cellRange.rowCount);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
// 循环添加所有行
|
|
887
|
+
else if (curDefaultPointCount > 1 && lastDefaultPointCount == 0) {
|
|
888
|
+
addRowsFun(cellRange.row + cellRange.rowCount, (curDefaultPointCount - 1) * cellRange.rowCount, curDefaultPointCount - 1);
|
|
889
|
+
}
|
|
890
|
+
// 恢复绘制
|
|
891
|
+
sheet.resumePaint();
|
|
892
|
+
},
|
|
816
893
|
};
|
|
817
894
|
|
|
818
895
|
/**
|
|
@@ -12802,10 +12879,10 @@ const FormulaUtils = {
|
|
|
12802
12879
|
}
|
|
12803
12880
|
}
|
|
12804
12881
|
//系数
|
|
12805
|
-
let coefficient = 1 / accuracy;
|
|
12882
|
+
let coefficient = rapidUtils.preciseCalc(1, accuracy, 'div'); // 1 / accuracy;
|
|
12806
12883
|
//换算后的修约值(=修约值*系数)
|
|
12807
12884
|
//注意:此处使用到了toFixed,目的是可能会存在精度的问题
|
|
12808
|
-
let roundingValCal = Number((roundingVal * coefficient).toFixed(8));
|
|
12885
|
+
let roundingValCal = rapidUtils.preciseCalc(roundingVal, coefficient, 'mul'); // Number((roundingVal * coefficient).toFixed(8));
|
|
12809
12886
|
/**
|
|
12810
12887
|
* 计算修约结果函数
|
|
12811
12888
|
* @param inputVal 换算后的修约值
|
|
@@ -12842,7 +12919,7 @@ const FormulaUtils = {
|
|
|
12842
12919
|
return inputVal;
|
|
12843
12920
|
};
|
|
12844
12921
|
//返回最终修约结果(=修约结果/系数)
|
|
12845
|
-
const retNum = calcRoundingRet(roundingValCal) / coefficient;
|
|
12922
|
+
const retNum = rapidUtils.preciseCalc(calcRoundingRet(roundingValCal), coefficient, 'div'); // calcRoundingRet(roundingValCal) / coefficient;
|
|
12846
12923
|
//获取修约精度中的小数位数
|
|
12847
12924
|
let accuracyStr = accuracy + '';
|
|
12848
12925
|
//如果修约精度中没有小数,则直接返回
|