From c5f6254bccd89a90abfa3a6d6728416983ebbb4c Mon Sep 17 00:00:00 2001 From: liuyang Date: Thu, 20 Aug 2020 20:43:42 +0800 Subject: [PATCH] fix(formula initialization bug): if formula has cross sheet param, initial this --- src/controllers/sheetmanage.js | 60 ++++++++++++++++++++++++++++++---- src/global/formula.js | 16 +++++---- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index da760a5a6..1afc7d26b 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -151,6 +151,22 @@ const sheetmanage = { return Store.luckysheetfile[i]; }, + getSheetByName: function(name) { + let _this = this; + + if(name == null){ + return null; + } + + for(let i=0;i0 && loadSheetUrl == ""){ + for(let i = 0;i{ + if(str.indexOf("!")>-1){ + let name = str.substr(0, str.indexOf('!')); + dataNameList[name] = true; + } + }); if(dataindex == null){ continue; } - + if(cache[dataindex.toString()] == null){ ret.push(dataindex); cache[dataindex.toString()] = 1; } - } + } + + for(let n in dataNameList){ + let sheet = this.getSheetByName(n); + if(sheet==null){ + continue; + } + + let dataindex = sheet.index; + + if(cache[dataindex.toString()] == null){ + ret.push(dataindex); + cache[dataindex.toString()] = 1; + } + } } if(chart != null){ diff --git a/src/global/formula.js b/src/global/formula.js index 83455e308..db5981c0f 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -3600,7 +3600,7 @@ const luckysheetformula = { "+": 2, "-": 2 }, - functionParser: function(txt) { + functionParser: function(txt, cellRangeFunction) { let _this = this; if (_this.operatorjson == null) { @@ -3672,7 +3672,7 @@ const luckysheetformula = { let bt = bracket.pop(); if(bracket.length == 0){ - function_str += _this.functionParser(str) + ")"; + function_str += _this.functionParser(str,cellRangeFunction) + ")"; str = ""; } else{ @@ -3699,7 +3699,7 @@ const luckysheetformula = { } else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) { if(bracket.length <= 1){ - function_str += _this.functionParser(str) + ","; + function_str += _this.functionParser(str,cellRangeFunction) + ","; str = ""; } else{ @@ -3717,7 +3717,7 @@ const luckysheetformula = { if ((s + s_next) in _this.operatorjson) { if(bracket.length == 0){ if($.trim(str).length > 0){ - cal2.unshift(_this.functionParser($.trim(str))); + cal2.unshift(_this.functionParser($.trim(str),cellRangeFunction)); } else if($.trim(function_str).length > 0){ cal2.unshift($.trim(function_str)); @@ -3746,7 +3746,7 @@ const luckysheetformula = { else { if(bracket.length == 0){ if($.trim(str).length > 0){ - cal2.unshift(_this.functionParser($.trim(str))); + cal2.unshift(_this.functionParser($.trim(str),cellRangeFunction)); } else if($.trim(function_str).length > 0){ cal2.unshift($.trim(function_str)); @@ -3790,7 +3790,11 @@ const luckysheetformula = { let endstr = ""; if (_this.iscelldata($.trim(str))) { - endstr = "luckysheet_getcelldata('" + $.trim(str) + "')"; + let str_nb = $.trim(str); + endstr = "luckysheet_getcelldata('" +str_nb + "')"; + if(typeof(cellRangeFunction)=="function"){ + cellRangeFunction(str_nb); + } } else { str = $.trim(str);