Commit 1dccad94 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

добавлена SUMPRODUCT.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47745 954022d7-b5bf-4e40-9824-e11837661b57
parent badc42cd
...@@ -1124,4 +1124,42 @@ ...@@ -1124,4 +1124,42 @@
ok(oParser.parse()); ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 14); strictEqual( oParser.calculate().getValue(), 14);
}) })
test("Test: \"SUMPRODUCT\"",function(){
oParser = new parserFormula("SUMPRODUCT({2,3})","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 5);
oParser = new parserFormula("SUMPRODUCT({2,3},{4,5})","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 23);
oParser = new parserFormula("SUMPRODUCT({2,3},{4,5},{2,2})","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 46);
oParser = new parserFormula("SUMPRODUCT({2,3;4,5},{2,2;3,4})","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 42);
ws.getRange2("N44").setValue("1");
ws.getRange2("N45").setValue("2");
ws.getRange2("N46").setValue("3");
ws.getRange2("N47").setValue("4");
ws.getRange2("O44").setValue("5");
ws.getRange2("O45").setValue("6");
ws.getRange2("O46").setValue("7");
ws.getRange2("O47").setValue("8");
ws.getRange2("P44").setValue("9");
ws.getRange2("P45").setValue("10");
ws.getRange2("P46").setValue("11");
ws.getRange2("P47").setValue("12");
oParser = new parserFormula("SUMPRODUCT(N44:N47,O44:O47,P44:P47)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 780);
})
}); });
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
*/ */
cFormulaFunction.LookupAndReference = { cFormulaFunction.LookupAndReference = {
'groupName' : "LookupAndReference", 'groupName' : "LookupAndReference",
'ADDRESS' : function(){ 'ADDRESS' : function(){
var r = new cBaseFunction("ADDRESS"); var r = new cBaseFunction("ADDRESS");
r.setArgumentsMin(2); r.setArgumentsMin(2);
r.setArgumentsMax(5); r.setArgumentsMax(5);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
*/ */
cFormulaFunction.Mathematic = { cFormulaFunction.Mathematic = {
'groupName' : "Mathematic", 'groupName' : "Mathematic",
'ABS' : function(){ 'ABS' : function(){
var r = new cBaseFunction("ABS"); var r = new cBaseFunction("ABS");
r.setArgumentsMin(1); r.setArgumentsMin(1);
r.setArgumentsMax(1); r.setArgumentsMax(1);
...@@ -2096,98 +2096,64 @@ cFormulaFunction.Mathematic = { ...@@ -2096,98 +2096,64 @@ cFormulaFunction.Mathematic = {
}, },
'SUMPRODUCT' : function(){ 'SUMPRODUCT' : function(){
var r = new cBaseFunction("SUMPRODUCT"); var r = new cBaseFunction("SUMPRODUCT");
/*r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = new cNumber(0), resArr = []; var arg0 = new cNumber( 0 ), resArr = [], col = 0, row = 0, res = 1, _res = [];
for(var i = 0; i < arg.length; i++){
for ( var i = 0; i < arg.length; i++ ) {
if( arg[i] instanceof cArea3D )
return this.value = new cError( bad_reference ); if ( arg[i] instanceof cArea3D )
return this.value = new cError( bad_reference );
if( arg[i] instanceof cArea ){
if ( arg[i] instanceof cArea || arg[i] instanceof cArray ){
function retCell(_cell){ resArr[i] = arg[i].getMatrix();
if(!_cell) if( row == 0 ) row = resArr[0].length;
return new cNumber(0); if( col == 0 ) col = resArr[0][0].length;
switch( _cell.getType() ){ }
case CellValueType.Number: else if ( arg[i] instanceof cRef || arg[i] instanceof cRef3D ) {
_cell.getValueWithoutFormat() == ""? return new cNumber(0) : return new cNumber( _cell.getValueWithoutFormat() ); resArr[i] = [[arg[i].getValue()]];
case CellValueType.Bool: }
return new cBool( _cell.getValueWithoutFormat() ).tocNumber(); else {
case CellValueType.Error: resArr[i] = [[arg[i]]];
return new cError( _cell.getValueWithoutFormat() ); }
case CellValueType.String:
default: if( row != resArr[i].length || col != resArr[i][0].length){
return new cNumber(0); return this.value = new cError( cErrorType.wrong_value_type );
} }
}
if ( arg[i] instanceof cError )
var argIBBox = arg[i].getBBox0(), return this.value = arg[i];
colCount = Math.abs(argIBBox.c2-argIBBox.c1)+1, }
rowCount = Math.abs(argIBBox.r2-argIBBox.r1)+1,
range = arg[i].getRange(); for( var iRow = 0; iRow < row; iRow++ ){
for( var iCol = 0; iCol < col; iCol++ ){
range._foreachIndex(function(i,j){ res=1;
for( var iRes = 0; iRes < resArr.length; iRes++){
}) arg0 = resArr[iRes][iRow][iCol];
if ( arg0 instanceof cError )
if( resArr.length == 0 ){ return this.value = arg0;
for( var i = 0; i < rowCount; i++ ){ else if(arg0 instanceof cString ){
resArr.push(new Array(colCount)); res *= 0;
} }
} else
else{ res *= arg0.tocNumber().getValue();
if( resArr.length == rowCount ){ }
if( resArr[0] == colCount ){ _res.push(res);
}
} }
else res = 0;
return this.value = new cError( not_numeric ); for(var i = 0; i < _res.length; i++)
} res += _res[i]
else
return this.value = new cError( not_numeric ); return this.value = new cNumber(res);
} }
r.getInfo = function () {
arg[i].foreach(function(oCurCell, i, j, r, c){ return {
name:this.name,
if( resArr[i] !== undefined && resArr[i] !== null ){ args:"( argument-lists )"
if( resArr[i][j] !== undefined && resArr[i][j] !== null ){ };
}
}
else{
resArr[i][j] = retCell(oCurCell);
}
}
else{
resArr[i] = [];
resArr[i][j] = !oCurCell ? new cNumber(0) :
}
})
}
else if( arg[i] instanceof cRef || arg[i] instanceof cRef3D ){
}
else if( arg[i] instanceof cArray ){
}
else{
}
if( arg[i] instanceof cError )
return this.value = arg0;
}
return this.value = arg0;
}
r.getInfo = function(){
return {
name:this.name,
args:"( argument-lists )"
};
}*/
return r; return r;
}, },
'SUMSQ' : function(){ 'SUMSQ' : function(){
......
...@@ -1724,6 +1724,39 @@ cArea.prototype.foreach = function(action){ ...@@ -1724,6 +1724,39 @@ cArea.prototype.foreach = function(action){
else else
r._foreach2(action) r._foreach2(action)
} }
cArea.prototype.getMatrix = function(){
var arr = [],
r = this.getRange();
r._foreach2(function(cell,i,j,r1,c1){
if( !arr[i-r1] )
arr[i-r1] = [];
if( cell ){
switch( cell.getType() ){
case CellValueType.Number:
arr[i-r1][j-c1] = cell.getValueWithoutFormat() == ""? new cEmpty() : new cNumber( cell.getValueWithoutFormat() )
break;
case CellValueType.Bool:
arr[i-r1][j-c1] = new cBool( cell.getValueWithoutFormat() );
break;
case CellValueType.Error:
arr[i-r1][j-c1] = new cError( cell.getValueWithoutFormat() );
break;
case CellValueType.String:
arr[i-r1][j-c1] = new cString( cell.getValueWithoutFormat() );
break;
default:
if( cell.getValueWithoutFormat() && cell.getValueWithoutFormat() != "" ){
arr[i-r1][j-c1] = new cNumber( cell.getValueWithoutFormat() )
}
else
arr[i-r1][j-c1] = checkTypeCell(""+cell.getValueWithoutFormat());
}
}
else
arr[i-r1][j-c1] = new cEmpty();
})
return arr;
}
/** @constructor */ /** @constructor */
function cRef(val,_ws){/*Ref means A1 for example*/ function cRef(val,_ws){/*Ref means A1 for example*/
...@@ -2242,6 +2275,9 @@ cArray.prototype.isValidArray = function(){ ...@@ -2242,6 +2275,9 @@ cArray.prototype.isValidArray = function(){
} }
return true; return true;
}; };
cArray.prototype.getMatrix = function(){
return this.array;
}
/** класс отвечающий за парсинг строки с формулой, подсчета формулы, перестройки формулы при манипуляции с ячейкой*/ /** класс отвечающий за парсинг строки с формулой, подсчета формулы, перестройки формулы при манипуляции с ячейкой*/
/** @constructor */ /** @constructor */
......
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