Commit 7432b07d authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

добавлена функция OFFSET;

подправлен парсинг для случая, когда вместо аргумента создавалась ошибка "#NAME?"
для примера, в файле \\192.168.5.2\source\DOCUMENTS\XLSX\Customer_Engagement_Workbook_3_0_FY08_External.xlsx на листе "Data" в ячейке Z2 есть формула: 
IF(ISERROR(VLOOKUP(ProdDD_180, INDIRECT("AnswerDDLookup_" & (V2)),2))," ", VLOOKUP(ProdDD_180, INDIRECT("AnswerDDLookup_" & (V2)),2))
так как имени "ProdDD_180" в таблицах нет, результат должен быть " ", у нас возвращалась ошибка "#NAME?"

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56019 954022d7-b5bf-4e40-9824-e11837661b57
parent 8cb5b00b
...@@ -280,7 +280,7 @@ parserHelper.prototype = { ...@@ -280,7 +280,7 @@ parserHelper.prototype = {
return true; return true;
} }
} }
this.operand_str = null; // this.operand_str = null;
return false; return false;
}, },
...@@ -296,7 +296,7 @@ parserHelper.prototype = { ...@@ -296,7 +296,7 @@ parserHelper.prototype = {
this.operand_str = match[0]; this.operand_str = match[0];
return true; return true;
} }
this.operand_str = null; // this.operand_str = null;
return false; return false;
}, },
...@@ -324,7 +324,7 @@ parserHelper.prototype = { ...@@ -324,7 +324,7 @@ parserHelper.prototype = {
} }
} }
this.operand_str = null; // this.operand_str = null;
return false; return false;
}, },
...@@ -341,7 +341,7 @@ parserHelper.prototype = { ...@@ -341,7 +341,7 @@ parserHelper.prototype = {
this.operand_str = match[1]; this.operand_str = match[1];
return [ true, match["name_from"] ? match["name_from"].replace( /''/g, "'" ) : null, match["name_to"] ? match["name_to"].replace( /''/g, "'" ) : null ]; return [ true, match["name_from"] ? match["name_from"].replace( /''/g, "'" ) : null, match["name_to"] ? match["name_to"].replace( /''/g, "'" ) : null ];
} }
this.operand_str = null; // this.operand_str = null;
return [false, null, null]; return [false, null, null];
}, },
...@@ -482,6 +482,7 @@ parserHelper.prototype = { ...@@ -482,6 +482,7 @@ parserHelper.prototype = {
this.operand_str = name; this.operand_str = name;
return [ true, name ]; return [ true, name ];
} }
this.operand_str = name;
} }
return [false]; return [false];
}, },
......
...@@ -361,15 +361,12 @@ ...@@ -361,15 +361,12 @@
return duration / p / frequency ; return duration / p / frequency ;
} }
var ver = 2; var oParser, wb, ws, dif = 1e-9,
var oParser, wb, ws, date1, date2, dif = 1e-9,
data = getTestWorkbook(), data = getTestWorkbook(),
sData = data + ""; sData = data + "";
if ( Asc.c_oSerFormat.Signature === sData.substring( 0, Asc.c_oSerFormat.Signature.length ) ) { if ( Asc.c_oSerFormat.Signature === sData.substring( 0, Asc.c_oSerFormat.Signature.length ) ) {
var sUrlPath = "offlinedocs/"; var sUrlPath = "offlinedocs/";
var wb = new Workbook( sUrlPath, new Asc.asc_CHandlersList(), {} ); wb = new Workbook( sUrlPath, new Asc.asc_CHandlersList(), {} );
// wb.initGlobalObjects();
History = new CHistory(wb); History = new CHistory(wb);
...@@ -390,8 +387,8 @@ ...@@ -390,8 +387,8 @@
var oBinaryFileReader = new Asc.BinaryFileReader( sUrlPath ); var oBinaryFileReader = new Asc.BinaryFileReader( sUrlPath );
oBinaryFileReader.Read( sData, wb ); oBinaryFileReader.Read( sData, wb );
}
ws = wb.getWorksheet( wb.getActive() ); ws = wb.getWorksheet( wb.getActive() );
}
/*QUnit.log( function ( details ) { /*QUnit.log( function ( details ) {
console.log( "Log: " + details.name + ", result - " + details.result ); console.log( "Log: " + details.name + ", result - " + details.result );
...@@ -3113,7 +3110,6 @@ ...@@ -3113,7 +3110,6 @@
/* /*
* Lookup and Reference * Lookup and Reference
*/ */
test( "Test: \"HLOOKUP\"", function () { test( "Test: \"HLOOKUP\"", function () {
ws.getRange2( "A401" ).setValue( "Axles" );ws.getRange2( "B401" ).setValue( "Bearings" );ws.getRange2( "C401" ).setValue( "Bolts" ); ws.getRange2( "A401" ).setValue( "Axles" );ws.getRange2( "B401" ).setValue( "Bearings" );ws.getRange2( "C401" ).setValue( "Bolts" );
...@@ -3277,10 +3273,37 @@ ...@@ -3277,10 +3273,37 @@
} ) } )
test( "Test: \"OFFSET\"", function () {
ws.getRange2( "C150" ).setValue( "1" );
ws.getRange2( "D150" ).setValue( "2" );
ws.getRange2( "E150" ).setValue( "3" );
ws.getRange2( "C151" ).setValue( "2" );
ws.getRange2( "D151" ).setValue( "3" );
ws.getRange2( "E151" ).setValue( "4" );
ws.getRange2( "C152" ).setValue( "3" );
ws.getRange2( "D152" ).setValue( "4" );
ws.getRange2( "E152" ).setValue( "5" );
oParser = new parserFormula( "OFFSET(C3,2,3,1,1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().toString(), "F5" );
oParser = new parserFormula( "SUM(OFFSET(C151:E155,-1,0,3,3))", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 27 );
oParser = new parserFormula( "OFFSET(B3; -2; 0; 1; 1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().toString(), "B1" );
} )
/* /*
* Financial * Financial
*/ */
test( "Test: \"FV\"", function () { test( "Test: \"FV\"", function () {
function fv( rate, nper, pmt, pv, type ) { function fv( rate, nper, pmt, pv, type ) {
...@@ -4699,6 +4722,4 @@ ...@@ -4699,6 +4722,4 @@
} ) } )
} ); } );
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
function _getRowTitle( row ) {
return "" + (row + 1);
}
cFormulaFunction.LookupAndReference = { cFormulaFunction.LookupAndReference = {
'groupName':"LookupAndReference", 'groupName':"LookupAndReference",
'ADDRESS':cADDRESS, 'ADDRESS':cADDRESS,
...@@ -52,10 +56,6 @@ function cADDRESS() { ...@@ -52,10 +56,6 @@ function cADDRESS() {
cADDRESS.prototype = Object.create( cBaseFunction.prototype ) cADDRESS.prototype = Object.create( cBaseFunction.prototype )
cADDRESS.prototype.Calculate = function ( arg ) { cADDRESS.prototype.Calculate = function ( arg ) {
function _getRowTitle( row ) {
return "" + (row + 1);
}
var rowNumber = arg[0], colNumber = arg[1], var rowNumber = arg[0], colNumber = arg[1],
refType = arg[2] ? arg[2] : new cNumber( 1 ), refType = arg[2] ? arg[2] : new cNumber( 1 ),
A1RefType = arg[3] ? arg[3] : new cBool( true ), A1RefType = arg[3] ? arg[3] : new cBool( true ),
...@@ -600,8 +600,9 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -600,8 +600,9 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
} }
if ( found_operand ) { if ( found_operand ) {
if ( found_operand instanceof cName ) if ( found_operand instanceof cName ){
found_operand = found_operand.toRef(); found_operand = found_operand.toRef();
}
var cellName = r.getCells()[0].getName(), wsId = r.worksheet.getId(); var cellName = r.getCells()[0].getName(), wsId = r.worksheet.getId();
...@@ -615,9 +616,10 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -615,9 +616,10 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
} }
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();
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, "" ) ); wb.dependencyFormulas.addEdge( wsId, cellName.replace( /\$/g, "" ), wsR[j].Id, found_operand._cells.replace( /\$/g, "" ) );
} }
}
return this.value = found_operand; return this.value = found_operand;
} }
...@@ -927,18 +929,135 @@ function cOFFSET() { ...@@ -927,18 +929,135 @@ function cOFFSET() {
} }
cOFFSET.prototype = Object.create( cBaseFunction.prototype ) cOFFSET.prototype = Object.create( cBaseFunction.prototype )
/* cOFFSET.prototype.Calculate = function ( arg ) { cOFFSET.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new cNumber(0 ), arg4 = arg[4] ? arg[4] : new cNumber(0);
function validCol( nCol ) {
return 0 <= nCol && nCol <= gc_nMaxCol;
}
function validRow( nRow ) {
return 0 <= nRow && nRow <= gc_nMaxRow;
}
function validBBOX( bbox ) {
return 0 <= bbox.r1 && bbox.r1 <= gc_nMaxRow0 &&
0 <= bbox.c1 && bbox.c1 <= gc_nMaxCol0 &&
0 <= bbox.r2 && bbox.r2 <= gc_nMaxRow0 &&
0 <= bbox.c2 && bbox.c2 <= gc_nMaxCol0;
}
var arg0 = arg[0],
arg1 = arg[1].tocNumber(),
arg2 = arg[2].tocNumber(),
arg3 = new cNumber( -1 ), arg4 = new cNumber( -1 );
if ( this.argumentsCurrent >= 4 ) {
arg3 = arg[3].tocNumber();
}
if ( this.argumentsCurrent == 5 ) {
arg4 = arg[4].tocNumber();
}
if ( arg1 instanceof cError || arg2 instanceof cError || arg3 instanceof cError || arg4 instanceof cError ) {
return this.value = new cError( cErrorType.bad_reference );
}
arg1 = arg1.getValue();
arg2 = arg2.getValue();
arg3 = arg3.getValue();
arg4 = arg4.getValue();
if ( arg3 < 0 ) {
arg3 = 1;
}
if ( arg4 < 0 ) {
arg4 = 1;
}
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
var range = arg0.getRange(),
bbox = range.getBBox0(),
box = {r1:0, r2:0, c1:0, c2:0}, ref;
box.r1 = bbox.r1 + arg1;
box.c1 = bbox.c1 + arg2;
box.r2 = bbox.r1 + arg1 + arg3 - 1;
box.c2 = bbox.c1 + arg2 + arg4 - 1;
if ( !validBBOX( box ) ) {
return this.value = new cError( cErrorType.bad_reference );
}
var wsName = arg0.ws.getName();
if ( box.r1 == box.r2 && box.c1 == box.c2 ) {
ref = g_oCellAddressUtils.colnumToColstrFromWsView( box.c1 + 1 ) + _getRowTitle( box.r1 );
this.value = (arg0 instanceof cRef) ? new cRef( ref, arg0.ws ) : new cRef3D( ref, wsName, arg0.wb );
}
else {
ref = g_oCellAddressUtils.colnumToColstrFromWsView( box.c1 + 1 ) + _getRowTitle( box.r1 ) + ":" +
g_oCellAddressUtils.colnumToColstrFromWsView( box.c2 + 1 ) + _getRowTitle( box.r2 );
this.value = (arg0 instanceof cRef) ? new cArea( ref, arg0.ws ) : new cArea3D( ref, wsName, wsName, arg0.wb );
}
}
else if ( arg0 instanceof cArea ) {
var bbox = arg0.getBBox0(),
box = {r1:0, r2:0, c1:0, c2:0}, ref;
if(1){} box.r1 = bbox.r1 + arg1;
box.c1 = bbox.c1 + arg2;
box.r2 = bbox.r1 + arg1 + arg3 - 1;
box.c2 = bbox.c1 + arg2 + arg4 - 1;
if ( !validBBOX( box ) ) {
return this.value = new cError( cErrorType.bad_reference );
}
if ( box.r1 == box.r2 && box.c1 == box.c2 ) {
ref = g_oCellAddressUtils.colnumToColstrFromWsView( box.c1 + 1 ) + _getRowTitle( box.r1 );
this.value = new cRef( ref, arg0.ws );
} }
cOFFSET.prototype.getInfo = function () { else {
ref = g_oCellAddressUtils.colnumToColstrFromWsView( box.c1 + 1 ) + _getRowTitle( box.r1 ) +
":" +
g_oCellAddressUtils.colnumToColstrFromWsView( box.c2 + 1 ) + _getRowTitle( box.r2 );
this.value = new cArea( ref, arg0.ws );
}
}
else {
this.value = new cError( cErrorType.wrong_value_type );
}
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.getCells()[0].getName(), wsId = r.worksheet.getId();
if ( (this.value instanceof cRef || this.value instanceof cRef3D || this.value instanceof cArea) && this.value.isValid() ) {
var nFrom = wb.dependencyFormulas.addNode( wsId, cellName ),
nTo = wb.dependencyFormulas.addNode( this.value.getWsId(), this.value._cells );
this.value.setNode( nTo );
wb.dependencyFormulas.addEdge2( nFrom, nTo );
}
else if ( this.value instanceof cArea3D && this.value.isValid() ) {
var wsR = this.value.wsRange();
for ( var j = 0; j < wsR.length; j++ ){
wb.dependencyFormulas.addEdge( wsId, cellName.replace( /\$/g, "" ), wsR[j].Id, this.value._cells.replace( /\$/g, "" ) );
}
}
}
return this.value;
}
cOFFSET.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( reference , rows , cols [ , [ height ] [ , [ width ] ] ] )" args:"( reference , rows , cols [ , [ height ] [ , [ width ] ] ] )"
}; };
} */ }
function cROW() { function cROW() {
// cBaseFunction.call( this, "ROW" ); // cBaseFunction.call( this, "ROW" );
......
...@@ -3146,6 +3146,9 @@ parserFormula.prototype = { ...@@ -3146,6 +3146,9 @@ parserFormula.prototype = {
return false;*/ return false;*/
this.outStack.push( new cError(cErrorType.wrong_name) ); this.outStack.push( new cError(cErrorType.wrong_name) );
operand_expected = false; operand_expected = false;
if( this.operand_str != null ){
this.pCurrPos += this.operand_str.length;
}
// break; // break;
/*this.outStack = [new cError(cErrorType.wrong_name)]; /*this.outStack = [new cError(cErrorType.wrong_name)];
return this.isParsed = false;*/ return this.isParsed = false;*/
...@@ -3321,6 +3324,7 @@ parserFormula.prototype = { ...@@ -3321,6 +3324,7 @@ parserFormula.prototype = {
} }
return this; return this;
}, },
setRefError:function ( wsId, cellId ) { setRefError:function ( wsId, cellId ) {
for ( var i = 0; i < this.outStack.length; i++ ) { for ( var i = 0; i < this.outStack.length; i++ ) {
var node = this.outStack[i]; var node = this.outStack[i];
...@@ -3601,6 +3605,7 @@ parserFormula.prototype = { ...@@ -3601,6 +3605,7 @@ parserFormula.prototype = {
} }
} }
}, },
insertSheet:function ( index ) { insertSheet:function ( index ) {
var bRes = false; var bRes = false;
for ( var i = 0; i < this.outStack.length; i++ ) { for ( var i = 0; i < this.outStack.length; i++ ) {
...@@ -3616,6 +3621,7 @@ parserFormula.prototype = { ...@@ -3616,6 +3621,7 @@ parserFormula.prototype = {
} }
return bRes; return bRes;
}, },
moveSheet:function ( tempW ) { moveSheet:function ( tempW ) {
var nRes = 0; var nRes = 0;
for ( var i = 0; i < this.outStack.length; i++ ) { for ( var i = 0; i < this.outStack.length; i++ ) {
......
...@@ -743,18 +743,24 @@ Vertex.prototype = { ...@@ -743,18 +743,24 @@ Vertex.prototype = {
}, },
//добавляем ведущую ячейку. //добавляем ведущую ячейку.
addMasterEdge : function(node){ addMasterEdge : function(node){
if( !this.masterEdges ) if( !this.masterEdges ){
this.masterEdges = {}; this.masterEdges = {};
}
if( !this.masterEdges[node.nodeId] ){
this.masterEdges[node.nodeId] = node; this.masterEdges[node.nodeId] = node;
this.refCount ++; this.refCount ++;
}
}, },
//добавляем зависимую(ведомую) ячейку. //добавляем зависимую(ведомую) ячейку.
addSlaveEdge : function(node){ addSlaveEdge : function(node){
if( !this.slaveEdges ) if( !this.slaveEdges ){
this.slaveEdges = {}; this.slaveEdges = {};
}
if( !this.slaveEdges[node.nodeId] ){
this.slaveEdges[node.nodeId] = node; this.slaveEdges[node.nodeId] = node;
this.refCount ++; this.refCount ++;
}
}, },
getMasterEdges : function(){ getMasterEdges : function(){
......
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