Commit b9c29090 authored by konovalovsergey's avatar konovalovsergey

fix bug 19769

parent 657a1cce
...@@ -4938,13 +4938,13 @@ parserFormula.prototype.parse = function(local, digitDelim) { ...@@ -4938,13 +4938,13 @@ parserFormula.prototype.parse = function(local, digitDelim) {
}; };
/* Для обратной сборки функции иногда необходимо поменять ссылки на ячейки */ /* Для обратной сборки функции иногда необходимо поменять ссылки на ячейки */
parserFormula.prototype.changeOffset = function (offset) {//offset = AscCommonExcel.CRangeOffset parserFormula.prototype.changeOffset = function (offset, canResize) {//offset = AscCommonExcel.CRangeOffset
for (var i = 0; i < this.outStack.length; i++) { for (var i = 0; i < this.outStack.length; i++) {
this.changeOffsetElem(this.outStack[i], this.outStack, i, offset); this.changeOffsetElem(this.outStack[i], this.outStack, i, offset, canResize);
} }
return this; return this;
}; };
parserFormula.prototype.changeOffsetElem = function(elem, container, index, offset) {//offset = parserFormula.prototype.changeOffsetElem = function(elem, container, index, offset, canResize) {//offset =
// AscCommonExcel.CRangeOffset // AscCommonExcel.CRangeOffset
var range, bbox = null, isErr = false; var range, bbox = null, isErr = false;
if (cElementType.cell === elem.type || cElementType.cell3D === elem.type || if (cElementType.cell === elem.type || cElementType.cell3D === elem.type ||
...@@ -4959,7 +4959,7 @@ parserFormula.prototype.parse = function(local, digitDelim) { ...@@ -4959,7 +4959,7 @@ parserFormula.prototype.parse = function(local, digitDelim) {
bbox = elem.getBBox0(); bbox = elem.getBBox0();
} }
if (bbox) { if (bbox) {
if (bbox.setOffsetWithAbs(offset)) { if (bbox.setOffsetWithAbs(offset, canResize)) {
isErr = false; isErr = false;
if (cElementType.cellsRange3D === elem.type) { if (cElementType.cellsRange3D === elem.type) {
elem.bbox = bbox; elem.bbox = bbox;
......
...@@ -4080,13 +4080,13 @@ ...@@ -4080,13 +4080,13 @@
row.c[j] = oTempCell; row.c[j] = oTempCell;
if ( oTempCell.formulaParsed ) { if ( oTempCell.formulaParsed ) {
if(copyRange) { if(copyRange) {
oTempCell.formulaParsed.removeDependencies(); //todo rework after clone formulaParsed unparsed
oTempCell.formulaParsed.changeOffset(offset); oTempCell.formulaParsed.parse();
oTempCell.formulaParsed.Formula = oTempCell.formulaParsed.assemble(true); History.TurnOff();
this.workbook.dependencyFormulas.addToBuildDependencyCell(oTempCell); oTempCell.changeOffset(offset, false, true);
} else { History.TurnOn();
this.workbook.dependencyFormulas.addToChangedCell(oTempCell);
} }
this.workbook.dependencyFormulas.addToBuildDependencyCell(oTempCell);
} }
} }
} }
...@@ -4863,16 +4863,17 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){ ...@@ -4863,16 +4863,17 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
cell.removeHyperlink(); cell.removeHyperlink();
} }
}; };
Cell.prototype.setFormula = function(formula, bHistoryUndo) { Cell.prototype.setFormulaTemplate = function(bHistoryUndo, action) {
var DataOld = null; var DataOld = null;
var DataNew = null; var DataNew = null;
if (History.Is_On()) if (History.Is_On())
DataOld = this.getValueData(); DataOld = this.getValueData();
this.removeDependencies();
this.oValue.clean(); this.oValue.clean();
this.formulaParsed = new parserFormula(formula, this, this.ws); if (this.formulaParsed) {
this.ws.workbook.dependencyFormulas.addToBuildDependencyCell(this); this.formulaParsed.removeDependencies();
}
action(this);
if (History.Is_On()) { if (History.Is_On()) {
DataNew = this.getValueData(); DataNew = this.getValueData();
...@@ -4882,6 +4883,19 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){ ...@@ -4882,6 +4883,19 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
} }
}; };
Cell.prototype.setFormula = function(formula, bHistoryUndo) {
this.setFormulaTemplate(bHistoryUndo, function(cell){
cell.formulaParsed = new parserFormula(formula, cell, cell.ws);
cell.ws.workbook.dependencyFormulas.addToBuildDependencyCell(cell);
});
};
Cell.prototype.changeOffset = function(offset, canResize, bHistoryUndo) {
this.setFormulaTemplate(bHistoryUndo, function(cell){
cell.formulaParsed.changeOffset(offset, canResize);
cell.formulaParsed.Formula = cell.formulaParsed.assemble(true);
cell.formulaParsed.buildDependencies();
});
};
Cell.prototype.removeDependencies = function() { Cell.prototype.removeDependencies = function() {
//удаляем сторое значение //удаляем сторое значение
if (this.formulaParsed) { if (this.formulaParsed) {
...@@ -8005,8 +8019,8 @@ Range.prototype._foreachNoEmpty=function(action, excludeHiddenRows){ ...@@ -8005,8 +8019,8 @@ Range.prototype._foreachNoEmpty=function(action, excludeHiddenRows){
} }
var oUndoRedoBBox = new UndoRedoData_BBox({r1:nRowFirst0, c1:nColFirst0, r2:nLastRow0, c2:nLastCol0}); var oUndoRedoBBox = new UndoRedoData_BBox({r1:nRowFirst0, c1:nColFirst0, r2:nLastRow0, c2:nLastCol0});
oRes = new AscCommonExcel.UndoRedoData_SortData(oUndoRedoBBox, aSortData); oRes = new AscCommonExcel.UndoRedoData_SortData(oUndoRedoBBox, aSortData);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_Sort, this.worksheet.getId(), new Asc.Range(0, nRowFirst0, gc_nMaxCol0, nLastRow0), oRes);
this._sortByArray(oUndoRedoBBox, aSortData); this._sortByArray(oUndoRedoBBox, aSortData);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_Sort, this.worksheet.getId(), new Asc.Range(0, nRowFirst0, gc_nMaxCol0, nLastRow0), oRes);
} }
this.worksheet.workbook.dependencyFormulas.unlockRecal(); this.worksheet.workbook.dependencyFormulas.unlockRecal();
return oRes; return oRes;
...@@ -8079,15 +8093,14 @@ Range.prototype._foreachNoEmpty=function(action, excludeHiddenRows){ ...@@ -8079,15 +8093,14 @@ Range.prototype._foreachNoEmpty=function(action, excludeHiddenRows){
oTempCellsTo[nIndexTo] = rowTo.c[i]; oTempCellsTo[nIndexTo] = rowTo.c[i];
if(null != oCurCell) if(null != oCurCell)
{ {
var lastName = oCurCell.getName(); if (oCurCell.formulaParsed) {
oCurCell.changeOffset({offsetCol: 0, offsetRow: shift}, true, true);
}
oCurCell.moveVer(shift); oCurCell.moveVer(shift);
rowTo.c[i] = oCurCell; rowTo.c[i] = oCurCell;
if (oCurCell.formulaParsed) { if (oCurCell && oCurCell.getFormula()) {
History.TurnOff(); //for #Ref
var _p_ = oCurCell.formulaParsed.clone(null, oCurCell, this); this.worksheet.workbook.dependencyFormulas.addToChangedCell(oCurCell);
var assemb = _p_.changeOffset({offsetCol: 0, offsetRow: shift}).assemble(true);
oCurCell.setFormula(assemb);
History.TurnOn();
} }
} }
else else
......
...@@ -502,7 +502,7 @@ ...@@ -502,7 +502,7 @@
this.r1 = Math.min(this.r1, r); this.r1 = Math.min(this.r1, r);
this.r2 = Math.max(this.r2, r); this.r2 = Math.max(this.r2, r);
}; };
Range.prototype.setOffsetWithAbs = function(offset) { Range.prototype.setOffsetWithAbs = function(offset, canResize) {
var temp; var temp;
var offsetRow = offset.offsetRow; var offsetRow = offset.offsetRow;
var offsetCol = offset.offsetCol; var offsetCol = offset.offsetCol;
...@@ -520,8 +520,10 @@ ...@@ -520,8 +520,10 @@
this.r1 += offsetRow; this.r1 += offsetRow;
if (this.r1 < 0) { if (this.r1 < 0) {
this.r1 = 0; this.r1 = 0;
if (!canResize) {
return false; return false;
} }
}
if (this.r1 > gc_nMaxRow0) { if (this.r1 > gc_nMaxRow0) {
this.r1 = gc_nMaxRow0; this.r1 = gc_nMaxRow0;
return false; return false;
...@@ -531,8 +533,10 @@ ...@@ -531,8 +533,10 @@
this.c1 += offsetCol; this.c1 += offsetCol;
if (this.c1 < 0) { if (this.c1 < 0) {
this.c1 = 0; this.c1 = 0;
if (!canResize) {
return false; return false;
} }
}
if (this.c1 > gc_nMaxCol0) { if (this.c1 > gc_nMaxCol0) {
this.c1 = gc_nMaxCol0; this.c1 = gc_nMaxCol0;
return false; return false;
...@@ -546,9 +550,11 @@ ...@@ -546,9 +550,11 @@
} }
if (this.r2 > gc_nMaxRow0) { if (this.r2 > gc_nMaxRow0) {
this.r2 = gc_nMaxRow0; this.r2 = gc_nMaxRow0;
if (!canResize) {
return false; return false;
} }
} }
}
if (!isAbsCol2) { if (!isAbsCol2) {
this.c2 += offsetCol; this.c2 += offsetCol;
if (this.c2 < 0) { if (this.c2 < 0) {
...@@ -557,9 +563,11 @@ ...@@ -557,9 +563,11 @@
} }
if (this.c2 > gc_nMaxCol0) { if (this.c2 > gc_nMaxCol0) {
this.c2 = gc_nMaxCol0; this.c2 = gc_nMaxCol0;
if (!canResize) {
return false; return false;
} }
} }
}
//switch abs flag //switch abs flag
if (this.r1 > this.r2) { if (this.r1 > this.r2) {
temp = this.r1; temp = this.r1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment