From 7a2f8d02daf2cc0180adc56dafcfb1d1f6d022ec Mon Sep 17 00:00:00 2001 From: wbfsa Date: Mon, 19 Oct 2020 06:22:40 +0800 Subject: [PATCH] fix(index offset indirect fix): improve the overall execution efficiency of the function --- src/function/func.js | 37 ++- src/function/functionImplementation.js | 176 +++++++++---- src/global/formula.js | 333 ++++++++++++++++++------- src/global/method.js | 1 - src/index.html | 2 +- src/locale/en.js | 2 +- src/locale/es.js | 2 +- src/locale/zh.js | 2 +- 8 files changed, 412 insertions(+), 143 deletions(-) diff --git a/src/function/func.js b/src/function/func.js index fcf2247..ef6a041 100644 --- a/src/function/func.js +++ b/src/function/func.js @@ -1917,6 +1917,40 @@ function luckysheet_offset_check() { }); } + +function luckysheet_getSpecialReference(isCellFirst, param1, param2) { + let functionRange, rangeTxt; + if(isCellFirst){ + rangeTxt = param1; + functionRange = param2; + } + else{ + functionRange = param1; + rangeTxt = param2; + } + + if(functionRange.startCell.indexOf(":")>-1 || rangeTxt.indexOf(":")>-1){ + return error.v; + } + + + if(isCellFirst){ + return luckysheet_getcelldata(rangeTxt + ":" +functionRange.startCell); + } + else{ + let rangeT = rangeTxt, sheetName=""; + if(rangeTxt.indexOf("!")>-1){ + let rangetxtArr = rangeTxt.split("!"); + sheetName = rangetxtArr[0] + "!"; + rangeT = rangetxtArr[1]; + } + return luckysheet_getcelldata(sheetName + functionRange.startCell + ":" + rangeT); + } + + + +} + export { luckysheet_compareWith, luckysheet_getarraydata, @@ -1926,5 +1960,6 @@ export { luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check, - luckysheet_calcADPMM + luckysheet_calcADPMM, + luckysheet_getSpecialReference } \ No newline at end of file diff --git a/src/function/functionImplementation.js b/src/function/functionImplementation.js index a53b491..0a20cc6 100644 --- a/src/function/functionImplementation.js +++ b/src/function/functionImplementation.js @@ -1,6 +1,6 @@ import { luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue } from './func'; import { inverse } from './matrix_methods'; -import { getSheetIndex, getluckysheetfile } from '../methods/get'; +import { getSheetIndex, getluckysheetfile,getRangetxt } from '../methods/get'; import menuButton from '../controllers/menuButton'; import luckysheetSparkline from '../controllers/sparkline'; import formula from '../global/formula'; @@ -3098,6 +3098,7 @@ const functionImplementation = { return compute(function_num); } + function compute(function_num){ switch(function_num){ @@ -10301,7 +10302,8 @@ const functionImplementation = { let luckysheetfile = getluckysheetfile(); let index = getSheetIndex(Store.calculateSheetIndex); - let sheetdata = luckysheetfile[index].data; + let currentSheet = luckysheetfile[index]; + let sheetdata = currentSheet.data; // sheetdata = Store.flowdata; // if (formula.execFunctionGroupData != null) { // sheetdata = formula.execFunctionGroupData; @@ -10309,56 +10311,45 @@ const functionImplementation = { //计算 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 >= sheetdata.length || col < 0 || col >= sheetdata[0].length){ - return formula.error.r; - } + } + else{ - if (sheetdata[row][col] == null || isRealNull(sheetdata[row][col].v)){ - return 0; - } + } - if (formula.execFunctionGlobalData != null) { - let ef = formula.execFunctionGlobalData[row+"_"+col+"_"+Store.calculateSheetIndex]; - if(ef!=null){ - return ef.v; - } - } + if(formula.iscelldata(ref_text)){ + let cellrange = formula.getcellrange(ref_text); + let row = cellrange.row[0], col = cellrange.column[0]; - return sheetdata[row][col].v; - } - else{ + if (row < 0 || row >= sheetdata.length || col < 0 || col >= sheetdata[0].length){ return formula.error.r; } - } - else{ - if(formula.iscelldata(ref_text)){ - let cellrange = formula.getcellrange(ref_text); - let row = cellrange.row[0], col = cellrange.column[0]; - if (row < 0 || row >= sheetdata.length || col < 0 || col >= sheetdata[0].length){ - return formula.error.r; - } + if (sheetdata[row][col] == null || isRealNull(sheetdata[row][col].v)){ + return 0; + } - if (sheetdata[row][col] == null || isRealNull(sheetdata[row][col].v)){ - return 0; + let value = sheetdata[row][col].v; + if (formula.execFunctionGlobalData != null) { + let ef = formula.execFunctionGlobalData[row+"_"+col+"_"+Store.calculateSheetIndex]; + if(ef!=null){ + value = ef.v; } + } - if (formula.execFunctionGlobalData != null) { - let ef = formula.execFunctionGlobalData[row+"_"+col+"_"+Store.calculateSheetIndex]; - if(ef!=null){ - return ef.v; - } - } - return sheetdata[row][col].v; - } - else{ - return formula.error.r; - } + let retAll= { + "sheetName": currentSheet.name, + "startCell": ref_text, + "rowl": row, + "coll": col, + "data": value + }; + + return retAll; + } + else{ + return formula.error.r; } } catch (e) { @@ -10563,6 +10554,7 @@ const functionImplementation = { } var reference = arguments[0].startCell; + let sheetName = arguments[0].sheetName; //要偏移的行数 var rows = func_methods.getFirstValue(arguments[1]); @@ -10673,7 +10665,19 @@ const functionImplementation = { result.push(rowArr); } - return result; + + let retAll= { + "sheetName": sheetName, + "startCell": getRangetxt(Store.calculateSheetIndex, { + row: [cellRow0, cellRow1], + column: [cellCol0, cellCol1] + }), + "rowl": cellRow0, + "coll": cellCol0, + "data": result + }; + + return retAll; } catch (e) { var err = e; @@ -11192,7 +11196,7 @@ const functionImplementation = { //单元格区域或数组常量 var data_array = arguments[0]; var array = []; - + let isReference = false; if(getObjType(data_array) == "array"){ if(getObjType(data_array[0]) == "array" && !func_methods.isDyadicArr(data_array)){ return formula.error.v; @@ -11202,6 +11206,7 @@ const functionImplementation = { } else if(getObjType(data_array) == "object" && data_array.startCell != null){ array = func_methods.getCellDataDyadicArr(data_array, "number"); + isReference = true; } var rowlen = array.length, collen = array[0].length; @@ -11224,22 +11229,87 @@ const functionImplementation = { return column_num; } - if(!isRealNum(column_num)){ - return formula.error.v; - } - column_num = parseInt(column_num); - if(row_num <= 0 || column_num <= 0){ + if(row_num < 0 || (isRealNum(column_num) && column_num < 0)){ return formula.error.v; } - if(row_num > rowlen || column_num > collen){ + if(row_num > rowlen || (isRealNum(column_num) && column_num > collen)){ return formula.error.r; } - //计算 - return array[row_num - 1][column_num - 1]; + if(isReference){ + + var cellrange = formula.getcellrange(data_array.startCell); + var cellRow0 = cellrange["row"][0]; + var cellCol0 = cellrange["column"][0]; + + + let data = array; + if(row_num == 0 || column_num == 0){ + if(row_num==0){ + data = array[0]; + row_num = 1; + } + else{ + data = array[row_num-1]; + } + + if(isRealNum(column_num)){ + if(column_num==0){ + data = data[0]; + column_num = 1; + } + else{ + data = data[column_num-1] + } + } + else{ + column_num = 1; + } + } + else{ + if(!isRealNum(row_num)){ + row_num = 1; + } + + if(!isRealNum(column_num)){ + column_num = 1; + } + data = array[row_num - 1][column_num - 1]; + } + + let row_index = cellRow0 + row_num - 1, column_index = cellCol0 + column_num - 1; + + let retAll= { + "sheetName": data_array.sheetName, + "startCell": getRangetxt(Store.calculateSheetIndex, { + row: [row_index, row_index], + column: [column_index, column_index] + }), + "rowl": row_index, + "coll": column_index, + "data": data + }; + return retAll; + } + else{ + //计算 + + if(!isRealNum(column_num)){ + return formula.error.v; + } + + column_num = parseInt(column_num); + + if(row_num <= 0 || column_num <= 0){ + return formula.error.v; + } + return array[row_num - 1][column_num - 1]; + } + + } catch (e) { var err = e; @@ -20785,7 +20855,7 @@ const functionImplementation = { } try { - //包含要提取的字符的文本字符串 + //包含要提取���字符的文本字符串 var text = func_methods.getFirstValue(arguments[0], "text"); if(valueIsError(text)){ return text; @@ -26457,7 +26527,7 @@ const functionImplementation = { var cell_r = window.luckysheetCurrentRow; var cell_c = window.luckysheetCurrentColumn; var cell_fp = window.luckysheetCurrentFunction; - //色表,接下来会用到 + //色表,接下来���用到 var colorList = formula.colorList; var rangeValue = arguments[0]; diff --git a/src/global/formula.js b/src/global/formula.js index 62daf88..915f94d 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -23,9 +23,10 @@ import { jfrefreshgrid } from './refresh'; import { isInlineStringCell,convertSpanToShareString } from '../controllers/inlineString'; // import luckysheet_function from '../function/luckysheet_function'; // import functionlist from '../function/functionlist'; -import { luckysheet_compareWith, luckysheet_getarraydata, luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue, luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check,luckysheet_calcADPMM } from '../function/func'; +import { luckysheet_compareWith, luckysheet_getarraydata, luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue, luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check,luckysheet_calcADPMM,luckysheet_getSpecialReference } from '../function/func'; import Store from '../store'; import locale from '../locale/locale'; +import json from './json'; const luckysheetformula = { error: { @@ -704,7 +705,7 @@ const luckysheetformula = { sheettxt = val[0]; rangetxt = val[1]; - + sheettxt = sheettxt.replace(/\\'/g, "'"); if(sheettxt.substr(0,1)=="'" && sheettxt.substr(sheettxt.length-1,1)=="'"){ sheettxt = sheettxt.substring(1,sheettxt.length-1); } @@ -3829,6 +3830,12 @@ const luckysheetformula = { //=SUM(MAX(B1:C10,10)*5-100) + //=IFERROR(IF(ROW()-ROW($G$3)=1,$F4+$D4,SUM($D1:INDEX($D$4:$D$9,1,1),$F1:INDEX($F$4:$F$9,1,1))), "") + + //=IFERROR(IF(ROW()-ROW($G$3)=1,$F4+$D4,SUM(INDEX($D$4:$D$9,1,1):$D4,INDEX($F$4:$F$9,1,1):$F4)), "") + + //=SUM(I$4:OFFSET(I10,0,0)) + //bracket 0为运算符括号、1为函数括号 let cal1 = [], cal2 = [], bracket = []; @@ -3837,7 +3844,14 @@ const luckysheetformula = { if (s == "(" && matchConfig.dquote == 0 && matchConfig.braces == 0) { if (str.length > 0 && bracket.length == 0) { - function_str += "luckysheet_function." + str.toUpperCase() + ".f("; + str = str.toUpperCase(); + if(str.indexOf(":")>-1){ + let funcArray = str.split(":"); + function_str += "luckysheet_getSpecialReference(true,'"+ $.trim(funcArray[0]).replace(/'/g, "\\'") +"', luckysheet_function." + funcArray[1] + ".f(#lucky#"; + } + else{ + function_str += "luckysheet_function." + str + ".f("; + } bracket.push(1); str = ""; } @@ -3855,7 +3869,11 @@ const luckysheetformula = { let bt = bracket.pop(); if(bracket.length == 0){ - function_str += _this.functionParser(str,cellRangeFunction) + ")"; + let functionS = _this.functionParser(str,cellRangeFunction); + if(functionS.indexOf("#lucky#")>-1){ + functionS = functionS.replace(/#lucky#/g, "") + ")"; + } + function_str += functionS + ")"; str = ""; } else{ @@ -3892,7 +3910,11 @@ const luckysheetformula = { } else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) { if(bracket.length <= 1){ - function_str += _this.functionParser(str,cellRangeFunction) + ","; + let functionS = _this.functionParser(str,cellRangeFunction); + if(functionS.indexOf("#lucky#")>-1){ + functionS = functionS.replace(/#lucky#/g, "") + ")"; + } + function_str += functionS + ","; str = ""; } else{ @@ -3981,14 +4003,21 @@ const luckysheetformula = { if (i == funcstack.length - 1) { let endstr = ""; + let str_nb = $.trim(str).replace(/'/g, "\\'"); + if (_this.iscelldata(str_nb) && str_nb.substr(0,1)!=":") { - if (_this.iscelldata($.trim(str))) { - let str_nb = $.trim(str); - endstr = "luckysheet_getcelldata('" +str_nb.replace(/'/g, "\\'") + "')"; + endstr = "luckysheet_getcelldata('" +str_nb + "')"; if(typeof(cellRangeFunction)=="function"){ cellRangeFunction(str_nb); } - } + + } + else if(str_nb.substr(0,1)==":"){ + str_nb = str_nb.substr(1); + if(_this.iscelldata(str_nb)){ + endstr = "luckysheet_getSpecialReference(false," + function_str +",'"+ str_nb +"')"; + } + } else { str = $.trim(str); @@ -4190,7 +4219,28 @@ const luckysheetformula = { setluckysheetfile(luckysheetfile); }, isFunctionRangeSave: false, - isFunctionRangeSimple: function(txt, r, c, index,dynamicArray_compute) { + isFunctionRangeSimple:function(txt, r, c, index,dynamicArray_compute){ + if(txt==null || txt.length==0){ + return; + } + + let txtArray = txt.split(/==|!=|<>|<=|>=|[,()=+-\/*%&^><]/g); + if(txtArray.length>0){ + for(let i=0;i-1 || txt1.indexOf("OFFSET")>-1; + let isOffsetFunc = txt1.indexOf("INDIRECT(")>-1 || txt1.indexOf("OFFSET(")>-1 || txt1.indexOf("INDEX(")>-1; if(txt in this.formulaContainCellList){ let cellList = this.formulaContainCellList[txt]; if(isOffsetFunc){ @@ -4436,7 +4486,14 @@ const luckysheetformula = { if (s == "(" && matchConfig.dquote == 0 && matchConfig.braces == 0) { if (str.length > 0 && bracket.length == 0) { - function_str += "luckysheet_function." + str.toUpperCase() + ".f("; + str = str.toUpperCase(); + if(str.indexOf(":")>-1){ + let funcArray = str.split(":"); + function_str += "luckysheet_getSpecialReference(true,'"+ $.trim(funcArray[0]).replace(/'/g, "\\'") +"', luckysheet_function." + funcArray[1] + ".f(#lucky#"; + } + else{ + function_str += "luckysheet_function." + str + ".f("; + } bracket.push(1); str = ""; } @@ -4454,7 +4511,14 @@ const luckysheetformula = { let bt = bracket.pop(); if (bracket.length == 0) { - function_str += _this.isFunctionRange(str,r,c, index,dynamicArray_compute,cellRangeFunction) + ")"; + // function_str += _this.isFunctionRange(str,r,c, index,dynamicArray_compute,cellRangeFunction) + ")"; + // str = ""; + + let functionS = _this.isFunctionRange(str,r,c, index,dynamicArray_compute,cellRangeFunction); + if(functionS.indexOf("#lucky#")>-1){ + functionS = functionS.replace(/#lucky#/g, "") + ")"; + } + function_str += functionS + ")"; str = ""; } else { @@ -4479,9 +4543,26 @@ const luckysheetformula = { matchConfig.dquote += 1; } } + else if (s == "'") { + str += "'"; + + if (matchConfig.squote > 0) { + matchConfig.squote -= 1; + } + else { + matchConfig.squote += 1; + } + } else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) { if (bracket.length <= 1) { - function_str += _this.isFunctionRange(str, r, c, index,dynamicArray_compute,cellRangeFunction) + ","; + // function_str += _this.isFunctionRange(str, r, c, index,dynamicArray_compute,cellRangeFunction) + ","; + // str = ""; + + let functionS = _this.isFunctionRange(str, r, c, index,dynamicArray_compute,cellRangeFunction); + if(functionS.indexOf("#lucky#")>-1){ + functionS = functionS.replace(/#lucky#/g, "") + ")"; + } + function_str += functionS + ","; str = ""; } else { @@ -4560,7 +4641,8 @@ const luckysheetformula = { } } else { - if (matchConfig.dquote == 0) { + if (matchConfig.dquote == 0 && matchConfig.squote==0) { + str += $.trim(s); } else { @@ -4570,12 +4652,18 @@ const luckysheetformula = { if (i == funcstack.length - 1) { let endstr = ""; - - if (_this.iscelldata($.trim(str))) { - endstr = "luckysheet_getcelldata('" + $.trim(str) + "')"; - + let str_nb = $.trim(str).replace(/'/g, "\\'"); + if (_this.iscelldata(str_nb) && str_nb.substr(0,1)!=":") { + // endstr = "luckysheet_getcelldata('" + $.trim(str) + "')"; + endstr = "luckysheet_getcelldata('" +str_nb + "')"; _this.isFunctionRangeSaveChange(str, r, c, index, dynamicArray_compute); } + else if(str_nb.substr(0,1)==":"){ + str_nb = str_nb.substr(1); + if(_this.iscelldata(str_nb)){ + endstr = "luckysheet_getSpecialReference(false," + function_str +",'"+ str_nb +"')"; + } + } else { str = $.trim(str); @@ -4633,6 +4721,9 @@ const luckysheetformula = { let _this = this; if (r != null && c != null) { let range = _this.getcellrange($.trim(str), index); + if(range==null){ + return; + } let row = range.row, col = range.column, sheetIndex = range.sheetIndex; @@ -4678,66 +4769,99 @@ const luckysheetformula = { } }, checkSpecialFunctionRange: function (function_str, r, c, index, dynamicArray_compute,cellRangeFunction) { - 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 { - Store.calculateSheetIndex = index; - let str = eval(tempFunc); - - if(str instanceof Object && str.data!=null){ - str = str.data.v; - } - let str_nb = $.trim(str); - // console.log(function_str, tempFunc,str, this.iscelldata(str_nb),this.isFunctionRangeSave,r,c); - if (this.iscelldata(str_nb)) { - if(typeof(cellRangeFunction)=="function"){ - cellRangeFunction(str_nb); - } - this.isFunctionRangeSaveChange(str, r, c, index, dynamicArray_compute); - // console.log(function_str, str, this.isFunctionRangeSave,r,c); - } - } - catch{ - + + if(function_str.substr(0, 30) =="luckysheet_getSpecialReference" || function_str.substr(0, 20) == "luckysheet_function."){ + if(function_str.substr(0, 20) == "luckysheet_function."){ + let funcName = function_str.split(".")[1]; + if (funcName != null) { + funcName = funcName.toUpperCase(); + if (funcName != "INDIRECT" && funcName != "OFFSET" && funcName != "INDEX") { + return; } - - } - else if (funcName == "OFFSET") { - let tempFunc = "luckysheet_offset_check" + function_str.substr(28, function_str.length); - - try { - Store.calculateSheetIndex = index; - let str = eval(tempFunc); - if(str instanceof Object && str.data!=null){ - str = str.data.v; - } - let str_nb = $.trim(str); - if (this.iscelldata(str_nb)) { - if(typeof(cellRangeFunction)=="function"){ - cellRangeFunction(str_nb); - } - this.isFunctionRangeSaveChange(str, r, c, index,dynamicArray_compute); - //console.log(function_str, str, this.isFunctionRangeSave,r,c); - } - } - catch{ - + } + try { + Store.calculateSheetIndex = index; + let str = eval(function_str); + + if(str instanceof Object && str.startCell!=null){ + str = str.startCell; + } + let str_nb = $.trim(str); + // console.log(function_str, tempFunc,str, this.iscelldata(str_nb),this.isFunctionRangeSave,r,c); + if (this.iscelldata(str_nb)) { + if(typeof(cellRangeFunction)=="function"){ + cellRangeFunction(str_nb); } - //let result = eval(function_str); - - //console.log(function_str, result); + this.isFunctionRangeSaveChange(str, r, c, index, dynamicArray_compute); + // console.log(function_str, str, this.isFunctionRangeSave,r,c); } } + catch{ + } } + + // 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 { + // Store.calculateSheetIndex = index; + // let str = eval(tempFunc); + + // if(str instanceof Object && str.data!=null){ + // str = str.data.v; + // } + // let str_nb = $.trim(str); + // // console.log(function_str, tempFunc,str, this.iscelldata(str_nb),this.isFunctionRangeSave,r,c); + // if (this.iscelldata(str_nb)) { + // if(typeof(cellRangeFunction)=="function"){ + // cellRangeFunction(str_nb); + // } + // this.isFunctionRangeSaveChange(str, r, c, index, 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); + + // try { + // Store.calculateSheetIndex = index; + // let str = eval(tempFunc); + // if(str instanceof Object && str.data!=null){ + // str = str.data.v; + // } + // let str_nb = $.trim(str); + // if (this.iscelldata(str_nb)) { + // if(typeof(cellRangeFunction)=="function"){ + // cellRangeFunction(str_nb); + // } + // this.isFunctionRangeSaveChange(str, r, c, index,dynamicArray_compute); + // //console.log(function_str, str, this.isFunctionRangeSave,r,c); + // } + // } + // catch{ + + // } + // //let result = eval(function_str); + + // //console.log(function_str, result); + // } + // } + + // } }, execvertex: {}, execFunctionGroupData: null, @@ -4769,13 +4893,14 @@ const luckysheetformula = { } if(txt.indexOf("!")>-1){ + txt = txt.replace(/\\'/g, "'"); this.cellTextToIndexList[txt] = infoObj; } else{ this.cellTextToIndexList[txt+"_"+infoObj.sheetIndex] = infoObj; } - + // console.log(this.cellTextToIndexList); }, addToSheetIndexList:function(formulaTxt, sheetIndex, obIndex){ if(formulaTxt==null || formulaTxt.length==0){ @@ -4827,6 +4952,7 @@ const luckysheetformula = { window.luckysheet_indirect_check_return = luckysheet_indirect_check_return; window.luckysheet_offset_check = luckysheet_offset_check; window.luckysheet_calcADPMM = luckysheet_calcADPMM; + window.luckysheet_getSpecialReference = luckysheet_getSpecialReference; } if(_this.execFunctionGlobalData==null){ @@ -4931,37 +5057,61 @@ const luckysheetformula = { } } - // console.time("1"); + // while (stack.length > 0) { + // let u = stack.shift(); + + // } + + console.time("1"); + console.log(group.length); + let iii = 0, ii=0; + //先进先出法,构建逆向执行结构树 while (stack.length > 0) { let u = stack.shift(); - + let excludeList = {}; + _this.getChildrenVertex(u, vertex1, excludeList); + // ii++; + // console.log(JSON.stringify(excludeList)); for (let name in vertex1) { let item = vertex1[name]; if(item==null){ continue; } - if (u.r == item.r && u.c == item.c && u.index == item.index) { + + let ukey ="r" + u.r + "c" + u.c + "i" + u.index; + + // if ((u.r == item.r && u.c == item.c && u.index == item.index) || name in _this.execvertex[ukey].chidren ) { + // continue; + // } + + if(name in excludeList){ continue; } _this.isFunctionRangeSave = false; + + let calc_funcStr = getcellFormula(item.r, item.c, item.index); _this.isFunctionRangeSelect(calc_funcStr, u.r, u.c, u.index, dynamicArray_compute); + // iii++; + if (_this.isFunctionRangeSave) { if (!(name in _this.execvertex)) { + // console.log(JSON.stringify(item), JSON.stringify(u), _this.isFunctionRangeSave); + stack.push(item); _this.execvertex[name] = item; } count++; - _this.execvertex[name].chidren["r" + u.r + "c" + u.c + "i" + u.index] = 1; + _this.execvertex[name].chidren[ukey] = 1; } - // console.log(iii++); } } + // console.log(iii, ii); // console.timeEnd("1"); // console.time("2"); @@ -4981,9 +5131,21 @@ const luckysheetformula = { } } // console.timeEnd("2"); - // console.log(this.formulaContainCellList); + _this.execFunctionExist = null; }, + //递归得到引用节点 + getChildrenVertex:function(u, vertex1, obj){ + let ukey ="r" + u.r + "c" + u.c + "i" + u.index; + obj[ukey] = 1; + if(u.chidren !=null){ + for(let key in u.chidren){ + if(vertex1[key] && !(key in obj) ){ + this.getChildrenVertex(vertex1[key], vertex1, obj); + } + } + } + }, //深度优先算法,处理多级调用函数 functionDFS: function(u) { let _this = this; @@ -5198,7 +5360,7 @@ const luckysheetformula = { catch (e) { let err = e; //err错误提示处理 - console.log(e); + console.log(e,fp); err = _this.errorInfo(err); result = [_this.error.n, err]; } @@ -5209,12 +5371,15 @@ const luckysheetformula = { result = _this.error.v; } else{ - if(result.data == null || isRealNull(result.data.v)){ - result = 0; - } - else{ + if(getObjType(result.data)=="object" && !isRealNull(result.data.v)){ result = result.data.v; } + else if(!isRealNull(result.data)){ + result = result.data; + } + else { + result = 0; + } } } diff --git a/src/global/method.js b/src/global/method.js index 2a2e577..7e48c7c 100644 --- a/src/global/method.js +++ b/src/global/method.js @@ -180,7 +180,6 @@ const defaultConfig = { execFunctionGroupData: null, execFunctionExist: null, formulaContainSheetList:{}, - formulaContainCellList:{}, cellTextToIndexList:{}, isFunctionRangeSave: false, execvertex: {}, diff --git a/src/index.html b/src/index.html index 7a32ac1..6a2233b 100644 --- a/src/index.html +++ b/src/index.html @@ -53,7 +53,7 @@ "url":"./assets/iconfont/Pacifico-Regular.ttf" } ], - data: + data: [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart,sheetPicture,sheetDataVerification] /*[{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[ {"r":0,"c":0, diff --git a/src/locale/en.js b/src/locale/en.js index dc00356..05a87fd 100644 --- a/src/locale/en.js +++ b/src/locale/en.js @@ -3126,7 +3126,7 @@ export default { "t": 2, "d": "Returns the content of a cell, specified by row and column offset.", "a": "Content of cell specified by row and column offset.", - "m": [3, 3], + "m": [2, 3], "p": [{ "name": "reference", "detail": "The array of cells to be offset into.", diff --git a/src/locale/es.js b/src/locale/es.js index 35a63d4..b455ca2 100644 --- a/src/locale/es.js +++ b/src/locale/es.js @@ -3126,7 +3126,7 @@ export default { "t": 2, "d": "Returns the content of a cell, specified by row and column offset.", "a": "Content of cell specified by row and column offset.", - "m": [3, 3], + "m": [2, 3], "p": [{ "name": "reference", "detail": "The array of cells to be offset into.", diff --git a/src/locale/zh.js b/src/locale/zh.js index f9e0cfe..a72673f 100644 --- a/src/locale/zh.js +++ b/src/locale/zh.js @@ -3126,7 +3126,7 @@ export default { 't': 2, 'd': '返回表格或中的元素值,此元素由行号和列号的索引值给定。', 'a': '返回表格或中的元素值,此元素由行号和列号的索引值给定。', - 'm': [3, 3], + 'm': [2, 3], 'p': [{ 'name': 'array', 'detail': '单元格区域或数组常量。',