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.
...@@ -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++){
if( arg[i] instanceof cArea3D )
return this.value = new cError( bad_reference );
if( arg[i] instanceof cArea ){
function retCell(_cell){
if(!_cell)
return new cNumber(0);
switch( _cell.getType() ){
case CellValueType.Number:
_cell.getValueWithoutFormat() == ""? return new cNumber(0) : return new cNumber( _cell.getValueWithoutFormat() );
case CellValueType.Bool:
return new cBool( _cell.getValueWithoutFormat() ).tocNumber();
case CellValueType.Error:
return new cError( _cell.getValueWithoutFormat() );
case CellValueType.String:
default:
return new cNumber(0);
}
}
var argIBBox = arg[i].getBBox0(),
colCount = Math.abs(argIBBox.c2-argIBBox.c1)+1,
rowCount = Math.abs(argIBBox.r2-argIBBox.r1)+1,
range = arg[i].getRange();
range._foreachIndex(function(i,j){
}) for ( var i = 0; i < arg.length; i++ ) {
if( resArr.length == 0 ){ if ( arg[i] instanceof cArea3D )
for( var i = 0; i < rowCount; i++ ){ return this.value = new cError( bad_reference );
resArr.push(new Array(colCount));
}
}
else{
if( resArr.length == rowCount ){
if( resArr[0] == colCount ){
if ( arg[i] instanceof cArea || arg[i] instanceof cArray ){
resArr[i] = arg[i].getMatrix();
if( row == 0 ) row = resArr[0].length;
if( col == 0 ) col = resArr[0][0].length;
} }
else else if ( arg[i] instanceof cRef || arg[i] instanceof cRef3D ) {
return this.value = new cError( not_numeric ); resArr[i] = [[arg[i].getValue()]];
} }
else else {
return this.value = new cError( not_numeric ); resArr[i] = [[arg[i]]];
} }
arg[i].foreach(function(oCurCell, i, j, r, c){ if( row != resArr[i].length || col != resArr[i][0].length){
return this.value = new cError( cErrorType.wrong_value_type );
if( resArr[i] !== undefined && resArr[i] !== null ){
if( resArr[i][j] !== undefined && resArr[i][j] !== null ){
} }
else{
resArr[i][j] = retCell(oCurCell); if ( arg[i] instanceof cError )
} return this.value = arg[i];
}
else{
resArr[i] = [];
resArr[i][j] = !oCurCell ? new cNumber(0) :
} }
}) for( var iRow = 0; iRow < row; iRow++ ){
for( var iCol = 0; iCol < col; iCol++ ){
res=1;
for( var iRes = 0; iRes < resArr.length; iRes++){
arg0 = resArr[iRes][iRow][iCol];
if ( arg0 instanceof cError )
return this.value = arg0;
else if(arg0 instanceof cString ){
res *= 0;
} }
else if( arg[i] instanceof cRef || arg[i] instanceof cRef3D ){ else
res *= arg0.tocNumber().getValue();
} }
else if( arg[i] instanceof cArray ){ _res.push(res);
} }
else{
} }
res = 0;
for(var i = 0; i < _res.length; i++)
res += _res[i]
if( arg[i] instanceof cError ) return this.value = new cNumber(res);
return this.value = arg0;
}
return this.value = arg0;
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( argument-lists )" 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