diff --git a/.vs/luckysheet/config/applicationhost.config b/.vs/luckysheet/config/applicationhost.config new file mode 100644 index 0000000..7a99442 --- /dev/null +++ b/.vs/luckysheet/config/applicationhost.config @@ -0,0 +1,1025 @@ + + + + + + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.vs/luckysheet/v16/.suo b/.vs/luckysheet/v16/.suo new file mode 100644 index 0000000..d97978d Binary files /dev/null and b/.vs/luckysheet/v16/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..b11abad Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/src/controllers/dropCell.js b/src/controllers/dropCell.js index a7aebce..5f66952 100644 --- a/src/controllers/dropCell.js +++ b/src/controllers/dropCell.js @@ -470,7 +470,9 @@ const luckysheetDropCell = { if(cell.f != null){ let f = "=" + formula.functionCopy(cell.f, "down", j - apply_str_r + 1); - let v = formula.execfunction(f, j, i, true); + let v = formula.execfunction(f, j, i); + + formula.execFunctionGroup(j, i, v[1], undefined, d); cell.f = v[2]; cell.v = v[1]; @@ -552,7 +554,9 @@ const luckysheetDropCell = { if(cell.f != null){ let f = "=" + formula.functionCopy(cell.f, "up", apply_end_r - j + 1); - let v = formula.execfunction(f, j, i, true); + let v = formula.execfunction(f, j, i); + + formula.execFunctionGroup(j, i, v[1], undefined, d); cell.f = v[2]; cell.v = v[1]; @@ -644,7 +648,9 @@ const luckysheetDropCell = { if(cell.f != null){ let f = "=" + formula.functionCopy(cell.f, "right", j - apply_str_c + 1); - let v = formula.execfunction(f, i, j, true); + let v = formula.execfunction(f, i, j); + + formula.execFunctionGroup(j, i, v[1], undefined, d); cell.f = v[2]; cell.v = v[1]; @@ -726,7 +732,9 @@ const luckysheetDropCell = { if(cell.f != null){ let f = "=" + formula.functionCopy(cell.f, "left", apply_end_c - j + 1); - let v = formula.execfunction(f, i, j, true); + let v = formula.execfunction(f, i, j); + + formula.execFunctionGroup(j, i, v[1], undefined, d); cell.f = v[2]; cell.v = v[1]; diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index 1d38a16..f928cc3 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -753,8 +753,6 @@ const sheetmanage = { Store.flowdata = file["data"]; editor.webWorkerFlowDataCache(Store.flowdata);//worker存数据 - formula.execFunctionGroupData = null; - window.luckysheet_getcelldata_cache = null; luckysheetPostil.buildAllPs(Store.flowdata); diff --git a/src/function/func.js b/src/function/func.js index c027dcc..2511bfa 100644 --- a/src/function/func.js +++ b/src/function/func.js @@ -5,7 +5,7 @@ import { isRealNum, valueIsError } from '../global/validate'; import { getdatabyselectionD } from '../global/getdata'; import { genarate } from '../global/format'; import { inverse } from '../function/matrix_methods'; -import { getSheetIndex, getluckysheetfile } from '../methods/get'; +import { getSheetIndex, getluckysheetfile, getRangetxt } from '../methods/get'; import { getObjType, ABCatNum } from '../utils/util'; import Store from '../store'; @@ -1770,10 +1770,112 @@ function luckysheet_getValue() { } } + +function luckysheet_indirect_check() { + let cellTxt = arguments[0]; + if (cellTxt == null || cellTxt.length == 0) { + return null; + } + return cellTxt; +} + +function luckysheet_indirect_check_return(txt) { + return txt; +} + +function luckysheet_offset_check() { + if (!(getObjType(arguments[0]) == "object" && arguments[0].startCell != null)) { + return formula.error.v; + } + + var reference = arguments[0].startCell; + + //要偏移的行数 + var rows = func_methods.getFirstValue(arguments[1]); + if (valueIsError(rows)) { + return rows; + } + + if (!isRealNum(rows)) { + return formula.error.v; + } + + rows = parseInt(rows); + + //要偏移的列数 + var cols = func_methods.getFirstValue(arguments[2]); + if (valueIsError(cols)) { + return cols; + } + + if (!isRealNum(cols)) { + return formula.error.v; + } + + cols = parseInt(cols); + + //要从偏移目标开始返回的范围的高度 + var height = arguments[0].rowl; + if (arguments.length >= 4) { + height = func_methods.getFirstValue(arguments[3]); + if (valueIsError(height)) { + return height; + } + + if (!isRealNum(height)) { + return formula.error.v; + } + + height = parseInt(height); + } + + //要从偏移目标开始返回的范围的宽度 + var width = arguments[0].coll; + if (arguments.length == 5) { + width = func_methods.getFirstValue(arguments[4]); + if (valueIsError(width)) { + return width; + } + + if (!isRealNum(width)) { + return formula.error.v; + } + + width = parseInt(width); + } + + if (height < 1 || width < 1) { + return formula.error.r; + } + + //计算 + var cellrange = formula.getcellrange(reference); + var cellRow0 = cellrange["row"][0]; + var cellCol0 = cellrange["column"][0]; + + cellRow0 += rows; + cellCol0 += cols; + + var cellRow1 = cellRow0 + height - 1; + var cellCol1 = cellCol0 + width - 1; + + if (cellRow0 < 0 || cellRow1 >= Store.flowdata.length || cellCol0 < 0 || cellCol1 >= Store.flowdata[0].length) { + return formula.error.r; + } + + return getRangetxt(Store.currentSheetIndex, { + row: [cellRow0, cellRow1], + column: [cellCol0, cellCol1] + }); +} + export { luckysheet_compareWith, luckysheet_getarraydata, luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue, + luckysheet_indirect_check, + luckysheet_indirect_check_return, + luckysheet_offset_check } \ No newline at end of file diff --git a/src/function/functionImplementation.js b/src/function/functionImplementation.js index f9e540a..e62054c 100644 --- a/src/function/functionImplementation.js +++ b/src/function/functionImplementation.js @@ -10299,21 +10299,27 @@ const functionImplementation = { } } + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //计算 if(A1){ if(formula.iscelldata(ref_text)){ let cellrange = formula.getcellrange(ref_text); let row = cellrange.row[0], col = cellrange.column[0]; - if(row < 0 || row >= Store.flowdata.length || col < 0 || col >= Store.flowdata[0].length){ + if (row < 0 || row >= sheetdata.length || col < 0 || col >= sheetdata[0].length){ return formula.error.r; } - if(Store.flowdata[row][col] == null || isRealNull(Store.flowdata[row][col].v)){ + if (sheetdata[row][col] == null || isRealNull(sheetdata[row][col].v)){ return 0; } - return Store.flowdata[row][col].v; + return sheetdata[row][col].v; } else{ return formula.error.r; @@ -10324,15 +10330,15 @@ const functionImplementation = { let cellrange = formula.getcellrange(ref_text); let row = cellrange.row[0], col = cellrange.column[0]; - if(row < 0 || row >= Store.flowdata.length || col < 0 || col >= Store.flowdata[0].length){ + if (row < 0 || row >= sheetdata.length || col < 0 || col >= sheetdata[0].length){ return formula.error.r; } - if(Store.flowdata[row][col] == null || isRealNull(Store.flowdata[row][col].v)){ + if (sheetdata[row][col] == null || isRealNull(sheetdata[row][col].v)){ return 0; } - return Store.flowdata[row][col].v; + return sheetdata[row][col].v; } else{ return formula.error.r; @@ -10611,7 +10617,13 @@ const functionImplementation = { var cellRow1 = cellRow0 + height - 1; var cellCol1 = cellCol0 + width - 1; - if(cellRow0 < 0 || cellRow1 >= Store.flowdata.length || cellCol0 < 0 || cellCol1 >= Store.flowdata[0].length){ + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + + if (cellRow0 < 0 || cellRow1 >= sheetdata.length || cellCol0 < 0 || cellCol1 >= sheetdata[0].length){ return formula.error.r; } @@ -10621,8 +10633,8 @@ const functionImplementation = { var rowArr = []; for(var c = cellCol0; c <= cellCol1; c++){ - if(Store.flowdata[r][c] != null && !isRealNull(Store.flowdata[r][c].v)){ - rowArr.push(Store.flowdata[r][c].v); + if (sheetdata[r][c] != null && !isRealNull(sheetdata[r][c].v)){ + rowArr.push(sheetdata[r][c].v); } else{ rowArr.push(0); @@ -23288,6 +23300,12 @@ const functionImplementation = { var row_index = cellrange.row[0]; var col_index = cellrange.column[0]; + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + switch(info_type){ case "address": return reference; @@ -23299,28 +23317,28 @@ const functionImplementation = { return 0; break; case "contents": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].v == null || Store.flowdata[row_index][col_index].v ==""){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){ return 0; } - return Store.flowdata[row_index][col_index].v; + return sheetdata[row_index][col_index].v; break; case "filename": return file.name; break; case "format": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].ct == null){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].ct == null){ return "G"; } - return Store.flowdata[row_index][col_index].ct.fa; + return sheetdata[row_index][col_index].ct.fa; break; case "parentheses": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].v == null || Store.flowdata[row_index][col_index].v ==""){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){ return 0; } - if(Store.flowdata[row_index][col_index].v > 0){ + if (sheetdata[row_index][col_index].v > 0){ return 1; } else{ @@ -23328,17 +23346,17 @@ const functionImplementation = { } break; case "prefix": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].ht == null || Store.flowdata[row_index][col_index].v == null || Store.flowdata[row_index][col_index].v ==""){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].ht == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){ return ""; } - if(Store.flowdata[row_index][col_index].ht == 0){//居中对齐 + if (sheetdata[row_index][col_index].ht == 0){//居中对齐 return "^"; } - else if(Store.flowdata[row_index][col_index].ht == 1){//左对齐 + else if (sheetdata[row_index][col_index].ht == 1){//左对齐 return "'"; } - else if(Store.flowdata[row_index][col_index].ht == 2){//右对齐 + else if (sheetdata[row_index][col_index].ht == 2){//右对齐 return '"'; } else{ @@ -23352,7 +23370,7 @@ const functionImplementation = { return row_index + 1; break; case "type": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].v == null || Store.flowdata[row_index][col_index].v ==""){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){ return "b"; } @@ -25366,11 +25384,17 @@ const functionImplementation = { var minSpot = arguments[6]; var spotRadius = arguments[7]; + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -25506,8 +25530,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -25637,8 +25667,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -25779,8 +25815,14 @@ const functionImplementation = { } var offsetY = data[0].length; } + + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -25866,8 +25908,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26007,8 +26055,14 @@ const functionImplementation = { } var offsetY = data[0].length; } + + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26094,8 +26148,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26179,8 +26239,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26274,8 +26340,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26363,8 +26435,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26449,8 +26527,14 @@ const functionImplementation = { //定义需要格式化data数据 //var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; diff --git a/src/global/formula.js b/src/global/formula.js index 868a554..9515f77 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -20,7 +20,7 @@ import { luckysheetRangeLast } from './cursorPos'; import { jfrefreshgrid } from './refresh'; import luckysheet_function from '../function/luckysheet_function'; import functionlist from '../function/functionlist'; -import { luckysheet_compareWith, luckysheet_getcelldata } from '../function/func'; +import { luckysheet_compareWith, luckysheet_getcelldata, luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check } from '../function/func'; import Store from '../store'; const luckysheetformula = { @@ -1217,6 +1217,8 @@ const luckysheetformula = { } window.luckysheet_getcelldata_cache = null; + + let isRunExecFunction = true; let d = editor.deepCopyFlowData(Store.flowdata); @@ -1245,7 +1247,7 @@ const luckysheetformula = { else{ _this.delFunctionGroup(r, c); _this.execFunctionGroup(r, c, value); - + isRunExecFunction = false; curv = _this.execFunctionGroupData[r][c]; delete curv.f; @@ -1278,6 +1280,7 @@ const luckysheetformula = { else{ _this.delFunctionGroup(r, c); _this.execFunctionGroup(r, c, value); + isRunExecFunction = false; } } @@ -1325,10 +1328,10 @@ const luckysheetformula = { } if(RowlChange){ - jfrefreshgrid(d, [{"row": [r, r], "column": [c, c]}], cfg, null, RowlChange); + jfrefreshgrid(d, [{ "row": [r, r], "column": [c, c] }], cfg, null, RowlChange, isRunExecFunction); } - else{ - jfrefreshgrid(d, [{"row": [r, r], "column": [c, c]}]); + else { + jfrefreshgrid(d, [{ "row": [r, r], "column": [c, c] }], undefined, undefined, undefined, isRunExecFunction); } // Store.luckysheetCellUpdate.length = 0; //clear array @@ -3922,7 +3925,7 @@ const luckysheetformula = { setluckysheetfile(luckysheetfile); }, isFunctionRangeSave: false, - isFunctionRange: function(txt, r, c) { + isFunctionRange1: function(txt, r, c) { let _this = this; if (_this.operatorjson == null) { @@ -4020,12 +4023,12 @@ const luckysheetformula = { let row = range.row, col = range.column; - if((r + "_" + c) in dynamicArray_compute){ + if ((r + "_" + c) in dynamicArray_compute) { let isd_range = false; - for(let d_r = row[0]; d_r <= row[1]; d_r++){ - for(let d_c = col[0]; d_c <= col[1]; d_c++){ - if((d_r + "_" + d_c) in dynamicArray_compute && dynamicArray_compute[d_r + "_" + d_c].r == r && dynamicArray_compute[d_r + "_" + d_c].c == c){ + for (let d_r = row[0]; d_r <= row[1]; d_r++) { + for (let d_c = col[0]; d_c <= col[1]; d_c++) { + if ((d_r + "_" + d_c) in dynamicArray_compute && dynamicArray_compute[d_r + "_" + d_c].r == r && dynamicArray_compute[d_r + "_" + d_c].c == c) { isd_range = true; } } @@ -4033,38 +4036,367 @@ const luckysheetformula = { if (isd_range) { _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; - } + } else { _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; } } - else{ + else { if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1]) { _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; - } + } else { _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; } } - } + } else { let sheetlen = $.trim(str).split("!"); if (sheetlen.length > 1) { _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; - } + } else { _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; } } } + else { + //console.log(str); + } } i++; } + //console.log(function_str); + return function_str; + }, + isFunctionRange: function (txt, r, c) { + let _this = this; + if (_this.operatorjson == null) { + let arr = _this.operator.split("|"), + op = {}; + + for (let i = 0; i < arr.length; i++) { + op[arr[i].toString()] = 1; + } + + _this.operatorjson = op; + } + + if (txt.substr(0, 1) == "=") { + txt = txt.substr(1); + } + + let funcstack = txt.split(""); + let i = 0, + str = "", + function_str = "", + ispassby = true; + + let matchConfig = { + "bracket": 0, + "comma": 0, + "squote": 0, + "dquote": 0, + "compare": 0, + "braces": 0 + } + + let luckysheetfile = getluckysheetfile(); + let dynamicArray_compute = luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"] == null ? {} : luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"]; + + //bracket 0为运算符括号、1为函数括号 + let cal1 = [], cal2 = [], bracket = []; + + while (i < funcstack.length) { + let s = funcstack[i]; + + if (s == "(" && matchConfig.dquote == 0 && matchConfig.braces == 0) { + if (str.length > 0 && bracket.length == 0) { + function_str += "luckysheet_function." + str.toUpperCase() + ".f("; + bracket.push(1); + str = ""; + } + else if (bracket.length == 0) { + function_str += "("; + bracket.push(0); + str = ""; + } + else { + bracket.push(0); + str += s; + } + } + else if (s == ")" && matchConfig.dquote == 0 && matchConfig.braces == 0) { + let bt = bracket.pop(); + + if (bracket.length == 0) { + function_str += _this.isFunctionRange(str,r,c) + ")"; + str = ""; + } + else { + str += s; + } + } + else if (s == "{" && matchConfig.dquote == 0) { + str += '{'; + matchConfig.braces += 1; + } + else if (s == "}" && matchConfig.dquote == 0) { + str += '}'; + matchConfig.braces -= 1; + } + else if (s == '"') { + str += '"'; + + if (matchConfig.dquote > 0) { + matchConfig.dquote -= 1; + } + else { + matchConfig.dquote += 1; + } + } + else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) { + if (bracket.length <= 1) { + function_str += _this.isFunctionRange(str, r, c) + ","; + str = ""; + } + else { + str += ","; + } + } + else if (s in _this.operatorjson && matchConfig.dquote == 0 && matchConfig.braces == 0) { + let s_next = ""; + let op = _this.operatorPriority; + + if ((i + 1) < funcstack.length) { + s_next = funcstack[i + 1]; + } + + if ((s + s_next) in _this.operatorjson) { + if (bracket.length == 0) { + if ($.trim(str).length > 0) { + cal2.unshift(_this.isFunctionRange($.trim(str), r, c)); + } + else if ($.trim(function_str).length > 0) { + cal2.unshift($.trim(function_str)); + } + + if (cal1[0] in _this.operatorjson) { + let stackCeilPri = op[cal1[0]]; + + while (cal1.length > 0 && stackCeilPri != null) { + cal2.unshift(cal1.shift()); + stackCeilPri = op[cal1[0]]; + } + } + + cal1.unshift(s + s_next); + + function_str = ""; + str = ""; + } + else { + str += s + s_next; + } + + i++; + } + else { + if (bracket.length == 0) { + if ($.trim(str).length > 0) { + cal2.unshift(_this.isFunctionRange($.trim(str), r, c)); + } + else if ($.trim(function_str).length > 0) { + cal2.unshift($.trim(function_str)); + } + + if (cal1[0] in _this.operatorjson) { + let stackCeilPri = op[cal1[0]]; + stackCeilPri = stackCeilPri == null ? 1000 : stackCeilPri; + + let sPri = op[s]; + sPri = sPri == null ? 1000 : sPri; + + while (cal1.length > 0 && sPri >= stackCeilPri) { + cal2.unshift(cal1.shift()); + + stackCeilPri = op[cal1[0]]; + stackCeilPri = stackCeilPri == null ? 1000 : stackCeilPri; + } + } + + cal1.unshift(s); + + function_str = ""; + str = ""; + } + else { + str += s; + } + } + } + else { + if (matchConfig.dquote == 0) { + str += $.trim(s); + } + else { + str += s; + } + } + + if (i == funcstack.length - 1) { + let endstr = ""; + + if (_this.iscelldata($.trim(str))) { + endstr = "luckysheet_getcelldata('" + $.trim(str) + "')"; + + _this.isFunctionRangeSaveChange(str, r, c, dynamicArray_compute); + } + else { + str = $.trim(str); + + let regx = /{.*?}/; + if (regx.test(str) && str.substr(0, 1) != '"' && str.substr(str.length - 1, 1) != '"') { + let arraytxt = regx.exec(str)[0]; + let arraystart = str.search(regx); + let alltxt = ""; + + if (arraystart > 0) { + endstr += str.substr(0, arraystart); + } + + endstr += "luckysheet_getarraydata('" + arraytxt + "')"; + + if (arraystart + arraytxt.length < str.length) { + endstr += str.substr(arraystart + arraytxt.length, str.length); + } + } + else { + endstr = str; + } + } + + if (endstr.length > 0) { + cal2.unshift(endstr); + } + + if (cal1.length > 0) { + if (function_str.length > 0) { + cal2.unshift(function_str); + function_str = ""; + } + + while (cal1.length > 0) { + cal2.unshift(cal1.shift()); + } + } + + if (cal2.length > 0) { + function_str = _this.calPostfixExpression(cal2); + } + else { + function_str += endstr; + } + } + + i++; + } + //console.log(function_str); + _this.checkSpecialFunctionRange(function_str, r, c, dynamicArray_compute); return function_str; }, + isFunctionRangeSaveChange: function (str, r, c, dynamicArray_compute) { + let _this = this; + if (r != null && c != null) { + let range = _this.getcellrange($.trim(str)); + let row = range.row, + col = range.column; + + if ((r + "_" + c) in dynamicArray_compute) { + let isd_range = false; + + for (let d_r = row[0]; d_r <= row[1]; d_r++) { + for (let d_c = col[0]; d_c <= col[1]; d_c++) { + if ((d_r + "_" + d_c) in dynamicArray_compute && dynamicArray_compute[d_r + "_" + d_c].r == r && dynamicArray_compute[d_r + "_" + d_c].c == c) { + isd_range = true; + } + } + } + + if (isd_range) { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; + } + else { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; + } + } + else { + if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1]) { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; + } + else { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; + } + } + } + else { + let sheetlen = $.trim(str).split("!"); + + if (sheetlen.length > 1) { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; + } + else { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; + } + } + }, + checkSpecialFunctionRange: function (function_str, r, c, dynamicArray_compute) { + if (!window.luckysheet_indirect_check) { + window.luckysheet_indirect_check = luckysheet_indirect_check; + window.luckysheet_indirect_check_return = luckysheet_indirect_check_return; + window.luckysheet_offset_check = luckysheet_offset_check; + } + if (function_str.substr(0, 20) == "luckysheet_function.") { + let funcName = function_str.split(".")[1]; + if (funcName != null) { + funcName = funcName.toUpperCase(); + if (funcName == "INDIRECT") { + let tempFunc = "luckysheet_indirect_check" + function_str.substr(30, function_str.length); + + //tempFunc = tempFunc.replace(/luckysheet_getcelldata/g, "luckysheet_indirect_check_return"); + + try { + let str = eval(tempFunc); + if (this.iscelldata($.trim(str))) { + this.isFunctionRangeSaveChange(str, r, c, dynamicArray_compute); + console.log(function_str, str, this.isFunctionRangeSave,r,c); + } + } + catch{ + + } + } + else if (funcName == "OFFSET") { + let tempFunc = "luckysheet_offset_check" + function_str.substr(28, function_str.length); + + let str = eval(tempFunc); + if (this.iscelldata($.trim(str))) { + this.isFunctionRangeSaveChange(str, r, c, dynamicArray_compute); + + //console.log(function_str, str, this.isFunctionRangeSave,r,c); + } + + //let result = eval(function_str); + + //console.log(function_str, result); + } + } + + } + }, execvertex: {}, execFunctionGroupData: null, execFunctionExist: null, @@ -4332,10 +4664,10 @@ const luckysheetformula = { quotalen += quota2.length; } - if ((fp.substr(0, 16) == "luckysheet_function." || fp.substr(0, 18) == "luckysheet_compareWith") && funclen != quotalen / 2) { + if ((fp.substr(0, 20) == "luckysheet_function." || fp.substr(0, 22) == "luckysheet_compareWith") && funclen != quotalen / 2) { fp += ")"; - if(fp.substr(0, 16) == "luckysheet_function."){ + if(fp.substr(0, 20) == "luckysheet_function."){ txt += ")"; } @@ -4410,7 +4742,7 @@ const luckysheetformula = { let fp = $.trim(_this.functionParser(txt)); - if ((fp.substr(0, 16) == "luckysheet_function." || fp.substr(0, 18) == "luckysheet_compareWith") ) { + if ((fp.substr(0, 20) == "luckysheet_function." || fp.substr(0, 22) == "luckysheet_compareWith") ) { _this.functionHTMLIndex = 0; } diff --git a/src/global/refresh.js b/src/global/refresh.js index 7a28101..4f3abe8 100644 --- a/src/global/refresh.js +++ b/src/global/refresh.js @@ -18,19 +18,21 @@ import { createFilterOptions } from '../controllers/filter'; import { getSheetIndex } from '../methods/get'; import Store from '../store'; -function jfrefreshgrid(data, range, cfg, cdformat, RowlChange) { +function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction=true) { //单元格数据更新联动 - formula.execFunctionExist = []; - for(let s = 0; s < range.length; s++){ - for(let r = range[s].row[0]; r <= range[s].row[1]; r++){ - for(let c = range[s].column[0]; c <= range[s].column[1]; c++){ - formula.execFunctionExist.push({ "r": r, "c": c, "i": Store.currentSheetIndex }); + if (isRunExecFunction) { + formula.execFunctionExist = []; + for(let s = 0; s < range.length; s++){ + for(let r = range[s].row[0]; r <= range[s].row[1]; r++){ + for(let c = range[s].column[0]; c <= range[s].column[1]; c++){ + formula.execFunctionExist.push({ "r": r, "c": c, "i": Store.currentSheetIndex }); + } } } + formula.execFunctionExist.reverse(); + formula.execFunctionGroup(null, null, null, null, data); + formula.execFunctionGroupData = null; } - formula.execFunctionExist.reverse(); - formula.execFunctionGroup(null, null, null, null, data); - formula.execFunctionGroupData = null; if (Store.clearjfundo) { Store.jfundo = [];