rapid-spreadjs 1.0.49 → 1.0.51

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
@@ -791,6 +791,75 @@ const BusinessUtils = {
791
791
  sheet.resumePaint();
792
792
  return retData;
793
793
  },
794
+ /**
795
+ * 动态创建循环行
796
+ * @param GC GC对象
797
+ * @param spread 工作簿实例
798
+ * @param cellRange 单元格范围JSON对象,格式为:{row:0, col:0, rowCount:2, colCount:5}
799
+ * @param curDefaultPointCount 本次默认点数
800
+ * @param lastDefaultPointCount 上次默认点数,默认为:0(0代表首次创建)
801
+ * @param rowHeight 创建的行高度,默认为:24(单位为像素)
802
+ */
803
+ dynamicCreateCyclicRows: (GC, spread, cellRange, curDefaultPointCount, lastDefaultPointCount = 0, rowHeight = 24) => {
804
+ // 不进行动态创建行
805
+ if ((curDefaultPointCount <= 1 && lastDefaultPointCount == 0) || (curDefaultPointCount == lastDefaultPointCount && lastDefaultPointCount > 0)) {
806
+ return;
807
+ }
808
+ // 获取当前工作表
809
+ const sheet = spread.getActiveSheet();
810
+ /**
811
+ * 添加行
812
+ * @param addRowIndex 添加行的索引位置
813
+ * @param addRowCount 添加行的数量
814
+ * @param copyPointCount 复制点数的数量
815
+ * @param targetRowIndex 循环复制的时候,需要加上的行索引,默认为0
816
+ */
817
+ const addRowsFun = (addRowIndex, addRowCount, copyPointCount, targetRowIndex = 0) => {
818
+ // 添加需要循环的总行数
819
+ sheet.addRows(addRowIndex, addRowCount);
820
+ // 设置添加行的行高
821
+ for (let i = addRowIndex; i <= addRowIndex + addRowCount; i++) {
822
+ sheet.setRowHeight(i, rowHeight, GC.Spread.Sheets.SheetArea.viewport);
823
+ }
824
+ // 复制次数,每次复制到下方相邻位置
825
+ for (let i = 1; i <= copyPointCount; i++) {
826
+ // 计算目标起始行
827
+ const targetRow = cellRange.row + targetRowIndex + i * cellRange.rowCount;
828
+ // 使用sheet.copyTo方法进行复制
829
+ sheet.copyTo(cellRange.row, // 源起始行
830
+ cellRange.col, // 源起始列
831
+ targetRow, // 目标起始行
832
+ cellRange.col, // 目标起始列
833
+ cellRange.rowCount, // 源行数
834
+ cellRange.colCount, // 源列数
835
+ GC.Spread.Sheets.CopyToOptions.all // 复制内容类型(值、样式、公式等)
836
+ );
837
+ }
838
+ };
839
+ // 暂停绘制
840
+ sheet.suspendPaint();
841
+ // 当前默认点数<=1并且上一次默认点数>0的时候,则删除所有循环的行
842
+ if (curDefaultPointCount <= 1 && lastDefaultPointCount > 0) {
843
+ sheet.deleteRows(cellRange.row + cellRange.rowCount, (curDefaultPointCount - 1) * cellRange.rowCount);
844
+ }
845
+ // 当前默认点数>1并且上次默认点数>1的时候
846
+ else if (curDefaultPointCount > 1 && lastDefaultPointCount > 1) {
847
+ // 当前默认点数>上次默认点数时,则需要增加curDefaultPointCount-lastDefaultPointCount次循环
848
+ if (curDefaultPointCount > lastDefaultPointCount) {
849
+ addRowsFun(cellRange.row + cellRange.rowCount + (curDefaultPointCount - lastDefaultPointCount - 1) * cellRange.rowCount, (curDefaultPointCount - lastDefaultPointCount) * cellRange.rowCount, curDefaultPointCount - lastDefaultPointCount, (curDefaultPointCount - lastDefaultPointCount - 1) * cellRange.rowCount);
850
+ }
851
+ // 当前默认点数<上次默认点数时,则需要删除lastDefaultPointCount-curDefaultPointCount次循环所在的行
852
+ else if (curDefaultPointCount < lastDefaultPointCount) {
853
+ sheet.deleteRows(cellRange.row + cellRange.rowCount + (curDefaultPointCount - 1) * cellRange.rowCount, (lastDefaultPointCount - curDefaultPointCount) * cellRange.rowCount);
854
+ }
855
+ }
856
+ // 循环添加所有行
857
+ else if (curDefaultPointCount > 1 && lastDefaultPointCount == 0) {
858
+ addRowsFun(cellRange.row + cellRange.rowCount, (curDefaultPointCount - 1) * cellRange.rowCount, curDefaultPointCount - 1);
859
+ }
860
+ // 恢复绘制
861
+ sheet.resumePaint();
862
+ },
794
863
  };
795
864
 
796
865
  /**
@@ -18999,6 +19068,47 @@ const FormulaUtils = {
18999
19068
  return bzc;
19000
19069
  },
19001
19070
  },
19071
+ {
19072
+ funName: 'YJTREND',
19073
+ funDesc: '返回线性回归拟合线的一组纵坐标值(y值)',
19074
+ funDefaultVal: null,
19075
+ isAcceptArea: true,
19076
+ funParams: [
19077
+ {
19078
+ name: '已知的因变量值(y值)数组',
19079
+ repeatable: false,
19080
+ optional: false,
19081
+ },
19082
+ {
19083
+ name: '已知的自变量值(x值)数组',
19084
+ repeatable: false,
19085
+ optional: false,
19086
+ },
19087
+ {
19088
+ name: '希望预测y值的新x值',
19089
+ repeatable: false,
19090
+ optional: false,
19091
+ },
19092
+ ],
19093
+ funCallback: (spread, sheet, retData) => {
19094
+ //如果传递的参数小于3个,则返回空字符串
19095
+ if (retData.allCellValsEw.length < 3) {
19096
+ return '';
19097
+ }
19098
+ let xData = FormulaUtils.commFun.convertToInt(retData.allCellValsEw[0].filter((item) => FormulaUtils.commFun.isNumber(item))), yData = FormulaUtils.commFun.convertToInt(retData.allCellValsEw[1].filter((item) => FormulaUtils.commFun.isNumber(item))), x = retData.allCellValsEw[2];
19099
+ if (Array.isArray(x) && x.length > 0) {
19100
+ x = Number(x[0]);
19101
+ }
19102
+ else {
19103
+ x = Number(x);
19104
+ }
19105
+ console.log(111, retData);
19106
+ console.log(222, xData);
19107
+ console.log(333, yData);
19108
+ console.log(444, x);
19109
+ return 'OK';
19110
+ },
19111
+ },
19002
19112
  ],
19003
19113
  };
19004
19114