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

Commit

Permalink
feat(add autocalculationmerge sheet attribute): it can auto calculate…
Browse files Browse the repository at this point in the history
… merge infomation
  • Loading branch information
tubiaoge committed Aug 26, 2020
1 parent 99c4d62 commit f7e30cf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
49 changes: 46 additions & 3 deletions src/controllers/sheetmanage.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ const sheetmanage = {
}

let execF = function(){
_this.mergeCalculation(file["index"]);
_this.storeSheetParam();
_this.restoreselect();
_this.CacheNotLoadControll = [];
Expand Down Expand Up @@ -903,6 +904,48 @@ const sheetmanage = {
Store.luckysheetfile[index]["data"] = Store.flowdata;
Store.luckysheetfile[index]["config"] = $.extend(true, {}, Store.config);
},
mergeCalculationSheet:{},
mergeCalculation:function(index){
let file = Store.luckysheetfile[this.getSheetIndex(index)];
let config = file.config, data = file.data, mergeConfig = config.merge;
if(mergeConfig==null || index in this.mergeCalculationSheet || file["autoCalculationMerge"]===false){
return;
}

this.mergeCalculationSheet[index] = 1;

for(let x in mergeConfig){
let r = parseInt(x.substr(0, x.indexOf('_')));
let c = parseInt(x.substr(x.indexOf('_') + 1));
let mcInfo = mergeConfig[x];
if(data[r][c]==null){
data[r][c] = {};
}

data[r][c]["mc"] = {
r:r,
c:c,
rs:mcInfo.rs,
cs:mcInfo.cs,
}

for(let ir=r;ir<r+mcInfo.rs;ir++){
for(let ic=c;ic<c+mcInfo.cs;ic++){
if(ir==r && ic==c){
continue;
}
if(data[ir][ic]==null){
data[ir][ic] = {};
}
data[ir][ic]["mc"] = {
r:r,
c:c,
}
}
}

}
},
changeSheet: function(index, isPivotInitial, isNewSheet) {
if(isEditMode()){
// alert("非编辑模式下不允许该操作!");
Expand Down Expand Up @@ -941,7 +984,7 @@ const sheetmanage = {
if (load != null) {
_this.setSheetParam(true);
_this.showSheet();

_this.mergeCalculation(index);
setTimeout(function () {
formula.execFunctionGroup();
luckysheetrefreshgrid();
Expand All @@ -958,7 +1001,7 @@ const sheetmanage = {

_this.setSheetParam();
_this.showSheet();

_this.mergeCalculation(index);
setTimeout(function () {
_this.restoreCache();
formula.execFunctionGroupForce(luckysheetConfigsetting.forceCalculation);
Expand Down Expand Up @@ -1001,7 +1044,7 @@ const sheetmanage = {

_this.setSheetParam();
_this.showSheet();

_this.mergeCalculation(index);
setTimeout(function () {
_this.restoreCache();
formula.execFunctionGroupForce(luckysheetConfigsetting.forceCalculation);
Expand Down
6 changes: 6 additions & 0 deletions src/demoData/sheetCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const sheetCell = {
"c": 2,
"rs": 1,
"cs": 2
},
"15_10": {
"r": 15,
"c": 10,
"rs": 4,
"cs": 3
}
},
"borderInfo": [{
Expand Down

0 comments on commit f7e30cf

Please sign in to comment.