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

Commit

Permalink
fix(offset indirect formula fix): fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiaoge committed Sep 28, 2020
1 parent 9c80c57 commit d8dfe50
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 34 deletions.
51 changes: 40 additions & 11 deletions src/function/functionImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10299,11 +10299,13 @@ const functionImplementation = {
}
}

let sheetdata = null;
sheetdata = Store.flowdata;
if (formula.execFunctionGroupData != null) {
sheetdata = formula.execFunctionGroupData;
}
let luckysheetfile = getluckysheetfile();
let index = getSheetIndex(Store.calculateSheetIndex);
let sheetdata = luckysheetfile[index].data;
// sheetdata = Store.flowdata;
// if (formula.execFunctionGroupData != null) {
// sheetdata = formula.execFunctionGroupData;
// }

//计算
if(A1){
Expand All @@ -10319,6 +10321,13 @@ const functionImplementation = {
return 0;
}

if (formula.execFunctionGlobalData != null) {
let ef = formula.execFunctionGlobalData[row+"_"+col+"_"+Store.calculateSheetIndex];
if(ef!=null){
return ef.v;
}
}

return sheetdata[row][col].v;
}
else{
Expand All @@ -10338,6 +10347,13 @@ const functionImplementation = {
return 0;
}

if (formula.execFunctionGlobalData != null) {
let ef = formula.execFunctionGlobalData[row+"_"+col+"_"+Store.calculateSheetIndex];
if(ef!=null){
return ef.v;
}
}

return sheetdata[row][col].v;
}
else{
Expand Down Expand Up @@ -10617,11 +10633,15 @@ const functionImplementation = {
var cellRow1 = cellRow0 + height - 1;
var cellCol1 = cellCol0 + width - 1;

let sheetdata = null;
sheetdata = Store.flowdata;
if (formula.execFunctionGroupData != null) {
sheetdata = formula.execFunctionGroupData;
}
// let sheetdata = null;
// sheetdata = Store.flowdata;
// if (formula.execFunctionGroupData != null) {
// sheetdata = formula.execFunctionGroupData;
// }

let luckysheetfile = getluckysheetfile();
let index = getSheetIndex(Store.calculateSheetIndex);
let sheetdata = luckysheetfile[index].data;

if (cellRow0 < 0 || cellRow1 >= sheetdata.length || cellCol0 < 0 || cellCol1 >= sheetdata[0].length){
return formula.error.r;
Expand All @@ -10633,7 +10653,16 @@ const functionImplementation = {
var rowArr = [];

for(var c = cellCol0; c <= cellCol1; c++){
if (sheetdata[r][c] != null && !isRealNull(sheetdata[r][c].v)){
if(formula.execFunctionGlobalData != null && formula.execFunctionGlobalData[r+"_"+c+"_"+Store.calculateSheetIndex]!=null){
let ef = formula.execFunctionGlobalData[r+"_"+c+"_"+Store.calculateSheetIndex];
if(ef!=null){
rowArr.push(ef.v);
}
else{
rowArr.push(0);
}
}
else if (sheetdata[r][c] != null && !isRealNull(sheetdata[r][c].v)){
rowArr.push(sheetdata[r][c].v);
}
else{
Expand Down
86 changes: 63 additions & 23 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -4266,25 +4266,50 @@ const luckysheetformula = {
if(dynamicArray_compute==null){
dynamicArray_compute = {};
}

let _this = this;
let txt1 = txt.toUpperCase();
let isOffsetFunc = txt1.indexOf("INDIRECT")>-1 || txt1.indexOf("OFFSET")>-1;
if(txt in this.formulaContainCellList){
let cellList = this.formulaContainCellList[txt];
for(let cellStr in cellList){
this.isFunctionRangeSaveChange(cellStr, r, c, index, dynamicArray_compute);
if(isOffsetFunc){
let isoff = cellList["__LuckyisOff__"];
if(isoff==true){
for(let cellStr in cellList){
if(cellStr=="__LuckyisOff__"){
continue;
}
this.isFunctionRangeSaveChange(cellStr, r, c, index, dynamicArray_compute);
}
}
else{
this.isFunctionRange(txt, r, c, index,dynamicArray_compute, function(str){
_this.addToCellList(txt, str);
});
cellList["__LuckyisOff__"] = true;
}
}

else{

for(let cellStr in cellList){
if(cellStr=="__LuckyisOff__"){
continue;
}
this.isFunctionRangeSaveChange(cellStr, r, c, index, dynamicArray_compute);
}
}

return;
}

let txt1 = txt.toUpperCase();
if(txt1.indexOf("INDIRECT")>-1 || txt1.indexOf("OFFSET")>-1){

if(isOffsetFunc){
this.isFunctionRange(txt, r, c, index,dynamicArray_compute);
}
else{
this.isFunctionRangeSimple(txt, r, c, index,dynamicArray_compute);
}
},
isFunctionRange: function (txt, r, c, index,dynamicArray_compute) {
isFunctionRange: function (txt, r, c, index,dynamicArray_compute, cellRangeFunction) {
let _this = this;

if (_this.operatorjson == null) {
Expand Down Expand Up @@ -4346,7 +4371,7 @@ const luckysheetformula = {
let bt = bracket.pop();

if (bracket.length == 0) {
function_str += _this.isFunctionRange(str,r,c, index,dynamicArray_compute) + ")";
function_str += _this.isFunctionRange(str,r,c, index,dynamicArray_compute,cellRangeFunction) + ")";
str = "";
}
else {
Expand All @@ -4373,7 +4398,7 @@ const luckysheetformula = {
}
else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) {
if (bracket.length <= 1) {
function_str += _this.isFunctionRange(str, r, c, index,dynamicArray_compute) + ",";
function_str += _this.isFunctionRange(str, r, c, index,dynamicArray_compute,cellRangeFunction) + ",";
str = "";
}
else {
Expand All @@ -4391,7 +4416,7 @@ const luckysheetformula = {
if ((s + s_next) in _this.operatorjson) {
if (bracket.length == 0) {
if ($.trim(str).length > 0) {
cal2.unshift(_this.isFunctionRange($.trim(str), r, c, index,dynamicArray_compute));
cal2.unshift(_this.isFunctionRange($.trim(str), r, c, index,dynamicArray_compute,cellRangeFunction));
}
else if ($.trim(function_str).length > 0) {
cal2.unshift($.trim(function_str));
Expand Down Expand Up @@ -4420,7 +4445,7 @@ const luckysheetformula = {
else {
if (bracket.length == 0) {
if ($.trim(str).length > 0) {
cal2.unshift(_this.isFunctionRange($.trim(str), r, c, index,dynamicArray_compute));
cal2.unshift(_this.isFunctionRange($.trim(str), r, c, index,dynamicArray_compute,cellRangeFunction));
}
else if ($.trim(function_str).length > 0) {
cal2.unshift($.trim(function_str));
Expand Down Expand Up @@ -4517,8 +4542,8 @@ const luckysheetformula = {

i++;
}
//console.log(function_str);
_this.checkSpecialFunctionRange(function_str, r, c, index, dynamicArray_compute);
// console.log(function_str);
_this.checkSpecialFunctionRange(function_str, r, c, index, dynamicArray_compute,cellRangeFunction);
return function_str;
},
isFunctionRangeSaveChange: function (str, r, c, index, dynamicArray_compute) {
Expand All @@ -4527,9 +4552,9 @@ const luckysheetformula = {
let range = _this.getcellrange($.trim(str));
let row = range.row,
col = range.column,
index = range.sheetIndex;
sheetIndex = range.sheetIndex;

if ((r + "_" + c) in dynamicArray_compute && (Store.currentSheetIndex==index || index==null)) {
if ((r + "_" + c) in dynamicArray_compute && (index==sheetIndex || index==null)) {
let isd_range = false;

for (let d_r = row[0]; d_r <= row[1]; d_r++) {
Expand All @@ -4548,7 +4573,7 @@ const luckysheetformula = {
}
}
else {
if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1] && (Store.currentSheetIndex==index || index==null)) {
if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1] && (index==sheetIndex || index==null)) {
_this.isFunctionRangeSave = _this.isFunctionRangeSave || true;
}
else {
Expand All @@ -4569,7 +4594,7 @@ const luckysheetformula = {
// }
}
},
checkSpecialFunctionRange: function (function_str, r, c, index, dynamicArray_compute) {
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) {
Expand All @@ -4578,15 +4603,22 @@ const luckysheetformula = {
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;
}
if (this.iscelldata($.trim(str))) {
this.isFunctionRangeSaveChange(str, r, c, dynamicArray_compute);
//console.log(function_str, str, this.isFunctionRangeSave,r,c);
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{
Expand All @@ -4599,9 +4631,17 @@ const luckysheetformula = {
let tempFunc = "luckysheet_offset_check" + function_str.substr(28, function_str.length);

try {
Store.calculateSheetIndex = index;
let str = eval(tempFunc);
if (this.iscelldata($.trim(str))) {
this.isFunctionRangeSaveChange(str, r, c, dynamicArray_compute);
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);
}
}
Expand Down

0 comments on commit d8dfe50

Please sign in to comment.