Commit 28657cd1 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

падали при использорвании в именованных диапазонах функции OFFSET

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@65218 954022d7-b5bf-4e40-9824-e11837661b57
parent 0e1236ee
...@@ -472,6 +472,8 @@ cINDEX.prototype.Calculate = function ( arg ) { ...@@ -472,6 +472,8 @@ cINDEX.prototype.Calculate = function ( arg ) {
arg3 = arg[3] && !(arg[3] instanceof cEmpty) ? arg[3] : new cNumber(1), res; arg3 = arg[3] && !(arg[3] instanceof cEmpty) ? arg[3] : new cNumber(1), res;
if (arg0 instanceof cArea3D) { if (arg0 instanceof cArea3D) {
arg0 = arg0.tocArea();
if( !arg0 )
return this.value = new cError(cErrorType.not_available); return this.value = new cError(cErrorType.not_available);
} else if (arg0 instanceof cError) { } else if (arg0 instanceof cError) {
return this.value = arg0; return this.value = arg0;
...@@ -494,7 +496,14 @@ cINDEX.prototype.Calculate = function ( arg ) { ...@@ -494,7 +496,14 @@ cINDEX.prototype.Calculate = function ( arg ) {
} }
if (arg0 instanceof cArray || arg0 instanceof cArea) { if (arg0 instanceof cArray || arg0 instanceof cArea) {
var _a_ = arg0.getMatrix();
if( _a_.length == 1 ){/*одна строка*/
res = arg0.getValue2( 0, arg1 - 1);
}
else{
// console.log(_a_)
res = arg0.getValue2(arg1 - 1, arg2 - 1); res = arg0.getValue2(arg1 - 1, arg2 - 1);
}
} else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){ } else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if( (arg1 == 0 || arg1 == 1) && (arg2 ==0 || arg2 == 1) ){ if( (arg1 == 0 || arg1 == 1) && (arg2 ==0 || arg2 == 1) ){
res = arg0.tryConvert(); res = arg0.tryConvert();
...@@ -535,7 +544,11 @@ function cINDIRECT() { ...@@ -535,7 +544,11 @@ function cINDIRECT() {
cINDIRECT.prototype = Object.create( cBaseFunction.prototype ); cINDIRECT.prototype = Object.create( cBaseFunction.prototype );
cINDIRECT.prototype.Calculate = function ( arg ) { cINDIRECT.prototype.Calculate = function ( arg ) {
var t = this, arg0 = arg[0].tocString(), arg1 = arg[1] ? arg[1] : new cBool( true ), r = arguments[1], wb = r.worksheet.workbook, o = { Formula:"", pCurrPos:0 }, ref, found_operand; var t = this, arg0 = arg[0].tocString(),
arg1 = arg[1] ? arg[1] : new cBool( true ),
r1 = arguments[1], wb = r1.worksheet.workbook, o = { Formula:"", pCurrPos:0 },
r2 = arguments[2],
ref, found_operand;
function parseReference() { function parseReference() {
if ( (ref = parserHelp.is3DRef.call( o, o.Formula, o.pCurrPos ))[0] ) { if ( (ref = parserHelp.is3DRef.call( o, o.Formula, o.pCurrPos ))[0] ) {
...@@ -596,7 +609,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -596,7 +609,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
found_operand = found_operand.toRef(); found_operand = found_operand.toRef();
} }
var cellName = r.getFirst().getID(), wsId = r.worksheet.getId(); var cellName = r1.getFirst().getID(), wsId = r1.worksheet.getId();
if ( (found_operand instanceof cRef || found_operand instanceof cRef3D || found_operand instanceof cArea) && found_operand.isValid() ) { if ( (found_operand instanceof cRef || found_operand instanceof cRef3D || found_operand instanceof cArea) && found_operand.isValid() ) {
var nFrom = wb.dependencyFormulas.addNode( wsId, cellName ), var nFrom = wb.dependencyFormulas.addNode( wsId, cellName ),
...@@ -607,10 +620,18 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -607,10 +620,18 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
wb.dependencyFormulas.addEdge2( nFrom, nTo ); wb.dependencyFormulas.addEdge2( nFrom, nTo );
} }
else if ( found_operand instanceof cArea3D && found_operand.isValid() ) { else if ( found_operand instanceof cArea3D && found_operand.isValid() ) {
var wsR = found_operand.wsRange(); var wsR = found_operand.wsRange(),
nTo, nFrom, _cell = found_operand._cells.replace( /\$/g, "" );
for ( var j = 0; j < wsR.length; j++ ){ for ( var j = 0; j < wsR.length; j++ ){
wb.dependencyFormulas.addEdge( wsId, cellName.replace( /\$/g, "" ), wsR[j].Id, found_operand._cells.replace( /\$/g, "" ) ); if( r2 ){
nTo = wb.dependencyFormulas.addNode( wsR[j].Id, _cell ),
wb.dependencyFormulas.addEdge2( r2.defName, nTo );
}
else
wb.dependencyFormulas.addEdge( wsId, cellName.replace( /\$/g, "" ), wsR[j].Id, _cell );
} }
} }
return this.value = found_operand; return this.value = found_operand;
...@@ -1005,20 +1026,27 @@ cOFFSET.prototype.Calculate = function ( arg ) { ...@@ -1005,20 +1026,27 @@ cOFFSET.prototype.Calculate = function ( arg ) {
} }
if( this.value instanceof cArea || this.value instanceof cRef || this.value instanceof cRef3D || this.value instanceof cArea3D ){ if( this.value instanceof cArea || this.value instanceof cRef || this.value instanceof cRef3D || this.value instanceof cArea3D ){
var r = arguments[1], wb = r.worksheet.workbook, cellName = r.getFirst().getID(), wsId = r.worksheet.getId(); var r1 = arguments[1], r2 = arguments[2], wb = r1.worksheet.workbook, cellName = r1.getFirst().getID(), wsId = r1.worksheet.getId();
if ( (this.value instanceof cRef || this.value instanceof cRef3D || this.value instanceof cArea) && this.value.isValid() ) { if ( (this.value instanceof cRef || this.value instanceof cRef3D || this.value instanceof cArea) && this.value.isValid() ) {
var nFrom = wb.dependencyFormulas.addNode( wsId, cellName ), var nFrom = wb.dependencyFormulas.addNode( wsId, cellName ),
nTo = wb.dependencyFormulas.addNode( this.value.getWsId(), this.value._cells ); nTo = wb.dependencyFormulas.addNode( this.value.getWsId(), this.value._cells.replace( /\$/g, "" ) );
this.value.setNode( nTo ); this.value.setNode( nTo );
wb.dependencyFormulas.addEdge2( nFrom, nTo ); wb.dependencyFormulas.addEdge2( nFrom, nTo );
} }
else if ( this.value instanceof cArea3D && this.value.isValid() ) { else if ( this.value instanceof cArea3D && this.value.isValid() ) {
var wsR = this.value.wsRange(); var wsR = this.value.wsRange(),
nTo, nFrom, _cell = this.value._cells.replace( /\$/g, "" );
for ( var j = 0; j < wsR.length; j++ ){ for ( var j = 0; j < wsR.length; j++ ){
wb.dependencyFormulas.addEdge( wsId, cellName.replace( /\$/g, "" ), wsR[j].Id, this.value._cells.replace( /\$/g, "" ) ); if( r2 ){
nTo = wb.dependencyFormulas.addNode( wsR[j].Id, _cell ),
wb.dependencyFormulas.addEdge2( r2.defName, nTo );
}
else
wb.dependencyFormulas.addEdge( wsId, cellName.replace( /\$/g, "" ), wsR[j].Id, _cell );
} }
} }
} }
......
...@@ -878,6 +878,13 @@ cArea3D.prototype.tocString = function () { ...@@ -878,6 +878,13 @@ cArea3D.prototype.tocString = function () {
cArea3D.prototype.tocBool = function () { cArea3D.prototype.tocBool = function () {
return this.getValue()[0].tocBool(); return this.getValue()[0].tocBool();
}; };
cArea3D.prototype.tocArea = function () {
var wsR = this.wsRange();
if(wsR.length == 1){
return new cArea( this._cells, wsR[0] );
}
return false;
};
cArea3D.prototype.getWS = function () { cArea3D.prototype.getWS = function () {
return this.wsRange()[0]; return this.wsRange()[0];
}; };
...@@ -1312,7 +1319,7 @@ cName.prototype.getValue = function () { ...@@ -1312,7 +1319,7 @@ cName.prototype.getValue = function () {
return new cError( "#NAME?" ); return new cError( "#NAME?" );
} }
return this.defName.parsedRef.calculate(); return this.defName.parsedRef.calculate(this);
}; };
cName.prototype.getRef = function () { cName.prototype.getRef = function () {
...@@ -1342,7 +1349,7 @@ cName.prototype.Calculate = function(){ ...@@ -1342,7 +1349,7 @@ cName.prototype.Calculate = function(){
return new cError( cErrorType.wrong_name ); return new cError( cErrorType.wrong_name );
} }
return this.defName.parsedRef.calculate(); return this.defName.parsedRef.calculate(this);
}; };
...@@ -3278,6 +3285,7 @@ parserFormula.prototype = { ...@@ -3278,6 +3285,7 @@ parserFormula.prototype = {
while ( this.pCurrPos < this.Formula.length ) { while ( this.pCurrPos < this.Formula.length ) {
/*if ( parserHelp.isControlSymbols.call( this, this.Formula, this.pCurrPos )){ /*if ( parserHelp.isControlSymbols.call( this, this.Formula, this.pCurrPos )){
console.log("!");
continue; continue;
}*/ }*/
...@@ -3730,7 +3738,7 @@ parserFormula.prototype = { ...@@ -3730,7 +3738,7 @@ parserFormula.prototype = {
} }
}, },
calculate:function () { calculate:function (isDefName) {
if ( this.outStack.length < 1 ) { if ( this.outStack.length < 1 ) {
return this.value = new cError( cErrorType.wrong_name ); return this.value = new cError( cErrorType.wrong_name );
} }
...@@ -3750,7 +3758,7 @@ parserFormula.prototype = { ...@@ -3750,7 +3758,7 @@ parserFormula.prototype = {
for ( var ind = 0; ind < currentElement.getArguments(); ind++ ) { for ( var ind = 0; ind < currentElement.getArguments(); ind++ ) {
arg.unshift( elemArr.pop() ); arg.unshift( elemArr.pop() );
} }
_tmp = currentElement.Calculate( arg, this.ws.getCell( this.cellAddress ) ); _tmp = currentElement.Calculate( arg, this.ws.getCell( this.cellAddress ), isDefName );
if ( _tmp.numFormat !== undefined && _tmp.numFormat !== null ) { if ( _tmp.numFormat !== undefined && _tmp.numFormat !== null ) {
numFormat = _tmp.numFormat; //> numFormat ? _tmp.numFormat : numFormat; numFormat = _tmp.numFormat; //> numFormat ? _tmp.numFormat : numFormat;
} }
......
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