Commit 0f742b18 authored by Alexander.Trofimov's avatar Alexander.Trofimov

update changeOffset and assemble functions

parent b388cd4c
...@@ -4301,22 +4301,23 @@ parserFormula.prototype.getRef = function() { ...@@ -4301,22 +4301,23 @@ parserFormula.prototype.getRef = function() {
return aOutRef; return aOutRef;
}; };
/* Для обратной сборки функции иногда необходимо поменять ссылки на ячейки */ /* Для обратной сборки функции иногда необходимо поменять ссылки на ячейки */
parserFormula.prototype.changeOffset = function(offset) {//offset = {offsetCol:intNumber, offsetRow:intNumber} parserFormula.prototype.changeOffset = function (offset) {//offset = AscCommonExcel.CRangeOffset
var elem, r, a, b;
for (var i = 0; i < this.outStack.length; i++) { for (var i = 0; i < this.outStack.length; i++) {
if (this.outStack[i] instanceof cRef || this.outStack[i] instanceof cRef3D || this.outStack[i] instanceof cArea) { elem = this.outStack[i];
if (cElementType.cell === elem.type || cElementType.cell3D === elem.type ||
cElementType.cellsRange === elem.type) {
var r = this.outStack[i].getRange(); r = elem.getRange();
if (!r) { if (!r) {
break; break;
} }
if (this.outStack[i].isAbsolute) { if (elem.isAbsolute) {
this._changeOffsetHelper(this.outStack[i], offset); this._changeOffsetHelper(elem, offset);
} else { } else {
var a, b; if (cElementType.cellsRange === elem.type && (r.isColumn() && offset.offsetRow != 0 || r.isRow() && offset.offsetCol != 0)) {
if (this.outStack[i] instanceof cArea &&
(r.isColumn() && offset.offsetRow != 0 || r.isRow() && offset.offsetCol != 0)) {
continue; continue;
} }
r.setOffset(offset); r.setOffset(offset);
...@@ -4332,39 +4333,39 @@ parserFormula.prototype.changeOffset = function(offset) {//offset = {offsetCol:i ...@@ -4332,39 +4333,39 @@ parserFormula.prototype.changeOffset = function(offset) {//offset = {offsetCol:i
} }
if (a != b || this.outStack[i] instanceof cArea) { if (a != b || cElementType.cellsRange === elem.type) {
this.outStack[i].value = this.outStack[i]._cells = a + ":" + b; elem.value = elem._cells = a + ":" + b;
} else { } else {
this.outStack[i].value = this.outStack[i]._cells = a; elem.value = elem._cells = a;
} }
} }
continue; continue;
} }
if (this.outStack[i] instanceof cArea3D) { if (cElementType.cellsRange3D === elem.type) {
var r = this.outStack[i]._cells.indexOf(":") > -1 ? (new cArea(this.outStack[i]._cells, this.ws)) : r = elem._cells.indexOf(":") > -1 ? (new cArea(elem._cells, this.ws)) : (new cRef(elem._cells, this.ws));
(new cRef(this.outStack[i]._cells, this.ws));
var _r = r.getRange(); var _r = r.getRange();
if (!_r) { if (!_r) {
break; break;
} }
if (this.outStack[i].isAbsolute) { if (elem.isAbsolute) {
this._changeOffsetHelper(r, offset); this._changeOffsetHelper(r, offset);
} else { } else {
_r.setOffset(offset); _r.setOffset(offset);
var a = _r.first.getID(), b = _r.last.getID(); a = _r.first.getID();
b = _r.last.getID();
if (a != b) { if (a != b) {
r.value = r._cells = a + ":" + b; r.value = r._cells = a + ":" + b;
} else { } else {
r.value = r._cells = a; r.value = r._cells = a;
} }
} }
this.outStack[i]._cells = r._cells; elem._cells = r._cells;
} }
} }
return this; return this;
}; };
parserFormula.prototype.setRefError = function(node) { parserFormula.prototype.setRefError = function(node) {
//когда выставляется setRefError node не сдвигаются, поэтому node.cellId совпадает с elem._cells //когда выставляется setRefError node не сдвигаются, поэтому node.cellId совпадает с elem._cells
...@@ -4469,33 +4470,34 @@ parserFormula.prototype.changeSheet = function(lastName, newName) { ...@@ -4469,33 +4470,34 @@ parserFormula.prototype.changeSheet = function(lastName, newName) {
return this; return this;
}; };
/* Сборка функции в инфиксную форму */ /* Сборка функции в инфиксную форму */
parserFormula.prototype.assemble = function(rFormula) { parserFormula.prototype.assemble = function (rFormula) {
if (!rFormula && this.outStack.length == 1 && this.outStack[this.outStack.length - 1] instanceof cError) { if (!rFormula && this.outStack.length == 1 && this.outStack[this.outStack.length - 1] instanceof cError) {
return this.Formula; return this.Formula;
} }
var currentElement = null, _count = this.outStack.length, elemArr = new Array(_count), res = undefined, _count_arg; var currentElement = null, _count = this.outStack.length, elemArr = new Array(_count), res = undefined, _count_arg;
for (var i = 0, j = 0; i < _count; i++, j++) { for (var i = 0, j = 0; i < _count; i++, j++) {
currentElement = this.outStack[i]; currentElement = this.outStack[i];
if (currentElement.type == cElementType.operator || currentElement.type == cElementType.func) { if (cElementType.operator === currentElement.type || cElementType.func === currentElement.type) {
_count_arg = currentElement.getArguments(); _count_arg = currentElement.getArguments();
res = currentElement.Assemble2(elemArr, j - _count_arg, _count_arg); res = currentElement.Assemble2(elemArr, j - _count_arg, _count_arg);
j -= _count_arg; j -= _count_arg;
elemArr[j] = res; elemArr[j] = res;
} else { } else {
if (currentElement instanceof cString) { if (cElementType.string === currentElement.type) {
currentElement = new cString("\"" + currentElement.toString() + "\""); currentElement = new cString("\"" + currentElement.toString() + "\"");
} }
res = currentElement; res = currentElement;
elemArr[j] = res; elemArr[j] = res;
} }
} }
if (res != undefined && res != null) { if (res != undefined && res != null) {
return res.toString(); return res.toString();
} else { } else {
return this.Formula; return this.Formula;
} }
}; };
/* Сборка функции в инфиксную форму */ /* Сборка функции в инфиксную форму */
parserFormula.prototype.assembleLocale = function(locale, digitDelim) { parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
......
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