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.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { groupByJson, forEachJson, orderByJson, chunkJson } from 'rapid-utils';
|
|
1
|
+
import { groupByJson, forEachJson, orderByJson, chunkJson, preciseCalc } from 'rapid-utils';
|
|
2
2
|
import * as echarts from 'echarts';
|
|
3
3
|
import * as math from 'mathjs';
|
|
4
4
|
import { saveAs } from 'file-saver';
|
|
@@ -662,12 +662,13 @@ const BusinessUtils = {
|
|
|
662
662
|
* @param gc GC对象
|
|
663
663
|
* @param sheet 工作表实例
|
|
664
664
|
* @param testObjectAttrs 检测对象属性配置集合
|
|
665
|
+
* @param addRowIndex 添加检测对象属性区域的起始行索引,默认为:0
|
|
665
666
|
* @param isVertical 是否为纵表,默认为:true
|
|
666
667
|
* @param contentColStartIndex 表格内容列起始索引,默认为:1
|
|
667
668
|
* @param contentTotalColCount 表格内容列总数,默认为:77
|
|
668
|
-
* @param addRowHeight 添加的表格行高,默认为:24
|
|
669
|
+
* @param addRowHeight 添加的表格行高,默认为:24(单位为像素)
|
|
669
670
|
*/
|
|
670
|
-
createTestObjectAttrsCells: (gc, sheet, testObjectAttrs, isVertical = true, contentColStartIndex = 1, contentTotalColCount = 77, addRowHeight = 24) => {
|
|
671
|
+
createTestObjectAttrsCells: (gc, sheet, testObjectAttrs, addRowIndex = 0, isVertical = true, contentColStartIndex = 1, contentTotalColCount = 77, addRowHeight = 24) => {
|
|
671
672
|
if (!testObjectAttrs || testObjectAttrs.length === 0) {
|
|
672
673
|
return;
|
|
673
674
|
}
|
|
@@ -681,8 +682,14 @@ const BusinessUtils = {
|
|
|
681
682
|
const testObjectAttrsChunk = chunkJson(testObjectAttrs, rowTestObjectCount);
|
|
682
683
|
// 暂停绘制
|
|
683
684
|
sheet.suspendPaint();
|
|
684
|
-
// 设置工作表行数为0
|
|
685
|
-
sheet.setRowCount(0);
|
|
685
|
+
// // 设置工作表行数为0
|
|
686
|
+
// sheet.setRowCount(0);
|
|
687
|
+
// 获取当前Sheet的行数
|
|
688
|
+
const rowCount = sheet.getRowCount();
|
|
689
|
+
// 如果满足如下条件,则将末尾的行全部删除
|
|
690
|
+
if (addRowIndex > 0 && addRowIndex < rowCount) {
|
|
691
|
+
sheet.deleteRows(addRowIndex, rowCount - addRowIndex);
|
|
692
|
+
}
|
|
686
693
|
/**
|
|
687
694
|
* 设置单元格字体和大小
|
|
688
695
|
* @param row
|
|
@@ -750,11 +757,12 @@ const BusinessUtils = {
|
|
|
750
757
|
* 获取检测对象属性值集合
|
|
751
758
|
* @param sheet 工作表实例
|
|
752
759
|
* @param testObjectAttrs 检测对象属性配置集合
|
|
760
|
+
* @param addRowIndex 添加检测对象属性区域的起始行索引,默认为:0
|
|
753
761
|
* @param isVertical 是否为纵表,默认为:true
|
|
754
762
|
* @param contentColStartIndex 表格内容列起始索引,默认为:1
|
|
755
763
|
* @param contentTotalColCount 表格内容列总数,默认为:77
|
|
756
764
|
*/
|
|
757
|
-
getTestObjectAttrsVals: (sheet, testObjectAttrs, isVertical = true, contentColStartIndex = 1, contentTotalColCount = 77) => {
|
|
765
|
+
getTestObjectAttrsVals: (sheet, testObjectAttrs, addRowIndex = 0, isVertical = true, contentColStartIndex = 1, contentTotalColCount = 77) => {
|
|
758
766
|
// 一行中检测对象属性的个数(纵表为2个,横表为3个)
|
|
759
767
|
const rowTestObjectCount = isVertical ? 2 : 3;
|
|
760
768
|
// 将测试对象属性数据进行分块
|
|
@@ -763,7 +771,7 @@ const BusinessUtils = {
|
|
|
763
771
|
sheet.suspendPaint();
|
|
764
772
|
// 所有单元格对象
|
|
765
773
|
const allCells = SheetUtils.getAllCellObjsByRange(sheet, {
|
|
766
|
-
row:
|
|
774
|
+
row: addRowIndex,
|
|
767
775
|
col: contentColStartIndex,
|
|
768
776
|
rowCount: sheet.getRowCount(),
|
|
769
777
|
colCount: contentTotalColCount,
|
|
@@ -791,6 +799,75 @@ const BusinessUtils = {
|
|
|
791
799
|
sheet.resumePaint();
|
|
792
800
|
return retData;
|
|
793
801
|
},
|
|
802
|
+
/**
|
|
803
|
+
* 动态创建循环行
|
|
804
|
+
* @param GC GC对象
|
|
805
|
+
* @param spread 工作簿实例
|
|
806
|
+
* @param cellRange 单元格范围JSON对象,格式为:{row:0, col:0, rowCount:2, colCount:5}
|
|
807
|
+
* @param curDefaultPointCount 本次默认点数
|
|
808
|
+
* @param lastDefaultPointCount 上次默认点数,默认为:0(0代表首次创建)
|
|
809
|
+
* @param rowHeight 创建的行高度,默认为:24(单位为像素)
|
|
810
|
+
*/
|
|
811
|
+
dynamicCreateCyclicRows: (GC, spread, cellRange, curDefaultPointCount, lastDefaultPointCount = 0, rowHeight = 24) => {
|
|
812
|
+
// 不进行动态创建行
|
|
813
|
+
if ((curDefaultPointCount <= 1 && lastDefaultPointCount == 0) || (curDefaultPointCount == lastDefaultPointCount && lastDefaultPointCount > 0)) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
// 获取当前工作表
|
|
817
|
+
const sheet = spread.getActiveSheet();
|
|
818
|
+
/**
|
|
819
|
+
* 添加行
|
|
820
|
+
* @param addRowIndex 添加行的索引位置
|
|
821
|
+
* @param addRowCount 添加行的数量
|
|
822
|
+
* @param copyPointCount 复制点数的数量
|
|
823
|
+
* @param targetRowIndex 循环复制的时候,需要加上的行索引,默认为0
|
|
824
|
+
*/
|
|
825
|
+
const addRowsFun = (addRowIndex, addRowCount, copyPointCount, targetRowIndex = 0) => {
|
|
826
|
+
// 添加需要循环的总行数
|
|
827
|
+
sheet.addRows(addRowIndex, addRowCount);
|
|
828
|
+
// 设置添加行的行高
|
|
829
|
+
for (let i = addRowIndex; i <= addRowIndex + addRowCount; i++) {
|
|
830
|
+
sheet.setRowHeight(i, rowHeight, GC.Spread.Sheets.SheetArea.viewport);
|
|
831
|
+
}
|
|
832
|
+
// 复制次数,每次复制到下方相邻位置
|
|
833
|
+
for (let i = 1; i <= copyPointCount; i++) {
|
|
834
|
+
// 计算目标起始行
|
|
835
|
+
const targetRow = cellRange.row + targetRowIndex + i * cellRange.rowCount;
|
|
836
|
+
// 使用sheet.copyTo方法进行复制
|
|
837
|
+
sheet.copyTo(cellRange.row, // 源起始行
|
|
838
|
+
cellRange.col, // 源起始列
|
|
839
|
+
targetRow, // 目标起始行
|
|
840
|
+
cellRange.col, // 目标起始列
|
|
841
|
+
cellRange.rowCount, // 源行数
|
|
842
|
+
cellRange.colCount, // 源列数
|
|
843
|
+
GC.Spread.Sheets.CopyToOptions.all // 复制内容类型(值、样式、公式等)
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
// 暂停绘制
|
|
848
|
+
sheet.suspendPaint();
|
|
849
|
+
// 当前默认点数<=1并且上一次默认点数>0的时候,则删除所有循环的行
|
|
850
|
+
if (curDefaultPointCount <= 1 && lastDefaultPointCount > 0) {
|
|
851
|
+
sheet.deleteRows(cellRange.row + cellRange.rowCount, (curDefaultPointCount - 1) * cellRange.rowCount);
|
|
852
|
+
}
|
|
853
|
+
// 当前默认点数>1并且上次默认点数>1的时候
|
|
854
|
+
else if (curDefaultPointCount > 1 && lastDefaultPointCount > 1) {
|
|
855
|
+
// 当前默认点数>上次默认点数时,则需要增加curDefaultPointCount-lastDefaultPointCount次循环
|
|
856
|
+
if (curDefaultPointCount > lastDefaultPointCount) {
|
|
857
|
+
addRowsFun(cellRange.row + cellRange.rowCount + (curDefaultPointCount - lastDefaultPointCount - 1) * cellRange.rowCount, (curDefaultPointCount - lastDefaultPointCount) * cellRange.rowCount, curDefaultPointCount - lastDefaultPointCount, (curDefaultPointCount - lastDefaultPointCount - 1) * cellRange.rowCount);
|
|
858
|
+
}
|
|
859
|
+
// 当前默认点数<上次默认点数时,则需要删除lastDefaultPointCount-curDefaultPointCount次循环所在的行
|
|
860
|
+
else if (curDefaultPointCount < lastDefaultPointCount) {
|
|
861
|
+
sheet.deleteRows(cellRange.row + cellRange.rowCount + (curDefaultPointCount - 1) * cellRange.rowCount, (lastDefaultPointCount - curDefaultPointCount) * cellRange.rowCount);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
// 循环添加所有行
|
|
865
|
+
else if (curDefaultPointCount > 1 && lastDefaultPointCount == 0) {
|
|
866
|
+
addRowsFun(cellRange.row + cellRange.rowCount, (curDefaultPointCount - 1) * cellRange.rowCount, curDefaultPointCount - 1);
|
|
867
|
+
}
|
|
868
|
+
// 恢复绘制
|
|
869
|
+
sheet.resumePaint();
|
|
870
|
+
},
|
|
794
871
|
};
|
|
795
872
|
|
|
796
873
|
/**
|
|
@@ -12780,10 +12857,10 @@ const FormulaUtils = {
|
|
|
12780
12857
|
}
|
|
12781
12858
|
}
|
|
12782
12859
|
//系数
|
|
12783
|
-
let coefficient = 1 / accuracy;
|
|
12860
|
+
let coefficient = preciseCalc(1, accuracy, 'div'); // 1 / accuracy;
|
|
12784
12861
|
//换算后的修约值(=修约值*系数)
|
|
12785
12862
|
//注意:此处使用到了toFixed,目的是可能会存在精度的问题
|
|
12786
|
-
let roundingValCal = Number((roundingVal * coefficient).toFixed(8));
|
|
12863
|
+
let roundingValCal = preciseCalc(roundingVal, coefficient, 'mul'); // Number((roundingVal * coefficient).toFixed(8));
|
|
12787
12864
|
/**
|
|
12788
12865
|
* 计算修约结果函数
|
|
12789
12866
|
* @param inputVal 换算后的修约值
|
|
@@ -12820,7 +12897,7 @@ const FormulaUtils = {
|
|
|
12820
12897
|
return inputVal;
|
|
12821
12898
|
};
|
|
12822
12899
|
//返回最终修约结果(=修约结果/系数)
|
|
12823
|
-
const retNum = calcRoundingRet(roundingValCal) / coefficient;
|
|
12900
|
+
const retNum = preciseCalc(calcRoundingRet(roundingValCal), coefficient, 'div'); // calcRoundingRet(roundingValCal) / coefficient;
|
|
12824
12901
|
//获取修约精度中的小数位数
|
|
12825
12902
|
let accuracyStr = accuracy + '';
|
|
12826
12903
|
//如果修约精度中没有小数,则直接返回
|