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;i<Store.luckysheetfile.length;i++){ + let file = Store.luckysheetfile[i]; + if(file.name==name){ + return file; + } + } + + return null; + }, getCurSheetnoset: function() { let curindex = 0; @@ -731,7 +747,18 @@ const sheetmanage = { let loadSheetUrl = server.loadSheetUrl; - if(sheetindex.length == 0 || loadSheetUrl == ""){ + if(sheetindex.length == 0 && loadSheetUrl == ""){ + execF(); + } + else if(sheetindex.length>0 && loadSheetUrl == ""){ + for(let i = 0;i<sheetindex.length;i++){ + let item = sheetindex[i]; + let otherfile = Store.luckysheetfile[_this.getSheetIndex(item)]; + if(otherfile["load"] == null || otherfile["load"] == "0"){ + otherfile["data"] = _this.buildGridData(otherfile); + otherfile["load"] = "1"; + } + } execF(); } else{ @@ -1004,21 +1031,42 @@ const sheetmanage = { let ret= [], cache = {}; ret.push(file.index); cache[file.index.toString()] = 1; - if(calchain != null){ + let dataNameList = {}; for(let i = 0; i < calchain.length; i++){ - let func = calchain[i]; - let dataindex = func.index; + let f = calchain[i]; + let dataindex = f.index, func = f.func; + + formula.functionParser(func[2], (str)=>{ + 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);