Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(formula initialization bug): if formula has cross sheet param, in…
Browse files Browse the repository at this point in the history
…itial this
  • Loading branch information
tubiaoge committed Aug 20, 2020
1 parent 80bd5a4 commit c5f6254
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
60 changes: 54 additions & 6 deletions src/controllers/sheetmanage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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){
Expand Down
16 changes: 10 additions & 6 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -3600,7 +3600,7 @@ const luckysheetformula = {
"+": 2,
"-": 2
},
functionParser: function(txt) {
functionParser: function(txt, cellRangeFunction) {
let _this = this;

if (_this.operatorjson == null) {
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c5f6254

Please sign in to comment.