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

Commit

Permalink
fix(undo redo bug fix): formula update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiaoge committed Sep 29, 2020
1 parent 62f641f commit 373dc4f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 99 deletions.
11 changes: 8 additions & 3 deletions src/controllers/controlHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const controlHistory = {
sheetmanage.changeSheetExec(ctr.sheetIndex);
}

// formula.execFunctionExist = [];

if (ctr.type == "datachange") {
//如果有单元格为null,则对应公式应该删除
for(let s = 0; s < ctr.range.length; s++){
Expand All @@ -50,14 +52,14 @@ const controlHistory = {
if(r > ctr.data.length - 1){
break;
}

// formula.execFunctionExist.push({ "r": r, "c": c, "i": ctr.sheetIndex });
if(ctr.data[r][c] == null){
formula.delFunctionGroup(r,c);
}
}
}
}
formula.execFunctionGroup(null, null, null, null, ctr.data);//取之前的数据


let allParam = {
"cfg": ctr.config,
Expand All @@ -68,6 +70,7 @@ const controlHistory = {
}

jfrefreshgrid(ctr.data, ctr.range, allParam);
// formula.execFunctionGroup(null, null, null, null, ctr.data);//取之前的数据
}
else if (ctr.type == "pasteCut") {
let s = {
Expand Down Expand Up @@ -106,15 +109,17 @@ const controlHistory = {

for(let r = st_r;r < ed_r + 1; r++){
for(let c = st_c; c < ed_c +1; c++){
// formula.execFunctionExist.push({ "r": r, "c": c, "i": ctr.sheetIndex });
if(ctr.data[r][c] == null){
formula.delFunctionGroup(r,c);
}
}
}
}
formula.execFunctionGroup(null, null, null, null, ctr.data);//取之前的数据


jfrefreshrange(ctr.data, ctr.range, ctr.cdformat);
// formula.execFunctionGroup(null, null, null, null, ctr.data);//取之前的数据
}
else if (ctr.type == "resize") {
Store.config = ctr.config;
Expand Down
126 changes: 61 additions & 65 deletions src/function/functionImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23329,10 +23329,28 @@ const functionImplementation = {
var row_index = cellrange.row[0];
var col_index = cellrange.column[0];

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;

let value;
if(formula.execFunctionGlobalData != null && formula.execFunctionGlobalData[row_index+"_"+col_index+"_"+Store.calculateSheetIndex]!=null){
value = formula.execFunctionGlobalData[row_index+"_"+col_index+"_"+Store.calculateSheetIndex].v;
}
else if(sheetdata[row_index][col_index] != null && sheetdata[row_index][col_index].v != null && sheetdata[row_index][col_index].v !=""){
value = sheetdata[row_index][col_index];
if(value instanceof Object){
value = value.v;
}
}
else {
value = 0;
}

switch(info_type){
Expand All @@ -23346,11 +23364,11 @@ const functionImplementation = {
return 0;
break;
case "contents":
if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){
return 0;
}
// if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){
// value = 0;
// }

return sheetdata[row_index][col_index].v;
return value;
break;
case "filename":
return file.name;
Expand All @@ -23375,7 +23393,7 @@ const functionImplementation = {
}
break;
case "prefix":
if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].ht == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){
if (value==0){
return "";
}

Expand All @@ -23399,7 +23417,7 @@ const functionImplementation = {
return row_index + 1;
break;
case "type":
if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){
if (value==0){
return "b";
}

Expand Down Expand Up @@ -25413,11 +25431,9 @@ const functionImplementation = {
var minSpot = arguments[6];
var spotRadius = arguments[7];

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;

//定义需要格式化data数据
var dataformat = formula.readCellDataToOneArray(rangeValue);
Expand Down Expand Up @@ -25559,11 +25575,9 @@ const functionImplementation = {
//定义需要格式化data数据
var dataformat = formula.readCellDataToOneArray(rangeValue);

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;

//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
Expand Down Expand Up @@ -25696,11 +25710,9 @@ const functionImplementation = {
//定义需要格式化data数据
var dataformat = formula.readCellDataToOneArray(rangeValue);

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;

//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
Expand Down Expand Up @@ -25845,11 +25857,9 @@ const functionImplementation = {
var offsetY = data[0].length;
}

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;
//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
var width = cellSize[0];
Expand Down Expand Up @@ -25937,11 +25947,9 @@ const functionImplementation = {
//定义需要格式化data数据
var dataformat = formula.readCellDataToOneArray(rangeValue);

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;

//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
Expand Down Expand Up @@ -26085,11 +26093,9 @@ const functionImplementation = {
var offsetY = data[0].length;
}

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;
//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
var width = cellSize[0];
Expand Down Expand Up @@ -26177,11 +26183,9 @@ const functionImplementation = {
//定义需要格式化data数据
var dataformat = formula.readCellDataToOneArray(rangeValue);

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;

//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
Expand Down Expand Up @@ -26268,11 +26272,9 @@ const functionImplementation = {
//定义需要格式化data数据
var dataformat = formula.readCellDataToOneArray(rangeValue);

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;

//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
Expand Down Expand Up @@ -26369,11 +26371,9 @@ const functionImplementation = {
//定义需要格式化data数据
var dataformat = formula.readCellDataToOneArray(rangeValue);

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;

//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
Expand Down Expand Up @@ -26464,11 +26464,9 @@ const functionImplementation = {
//定义需要格式化data数据
var dataformat = formula.readCellDataToOneArray(rangeValue);

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;

//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
Expand Down Expand Up @@ -26556,11 +26554,9 @@ const functionImplementation = {
//定义需要格式化data数据
//var dataformat = formula.readCellDataToOneArray(rangeValue);

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;

//在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题
var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c);
Expand Down
12 changes: 8 additions & 4 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ const luckysheetformula = {
num = num % d;
return num;
},
getcellrange: function(txt) {
getcellrange: function(txt, formulaIndex) {
if(txt==null || txt.length==0){
return;
}
Expand Down Expand Up @@ -707,7 +707,11 @@ const luckysheetformula = {
}
}
else {
let index = getSheetIndex(Store.currentSheetIndex);
let i = formulaIndex;
if(i==null){
i = Store.currentSheetIndex;
}
let index = getSheetIndex(i);
sheettxt = luckysheetfile[index].name;
sheetIndex = luckysheetfile[index].index;
sheetdata = Store.flowdata;
Expand Down Expand Up @@ -4553,7 +4557,7 @@ const luckysheetformula = {
isFunctionRangeSaveChange: function (str, r, c, index, dynamicArray_compute) {
let _this = this;
if (r != null && c != null) {
let range = _this.getcellrange($.trim(str));
let range = _this.getcellrange($.trim(str), index);
let row = range.row,
col = range.column,
sheetIndex = range.sheetIndex;
Expand Down Expand Up @@ -4822,7 +4826,7 @@ const luckysheetformula = {
}

// console.time("1");
let iii =0;

while (stack.length > 0) {
let u = stack.shift();

Expand Down
Loading

0 comments on commit 373dc4f

Please sign in to comment.