Commit ed86a6d8 authored by Alexander.Trofimov's avatar Alexander.Trofimov

instanceof -> check type

parent 019d7ae0
......@@ -3802,26 +3802,27 @@ cSQRTPI.prototype.getInfo = function () {
};
}
function cSUBTOTAL() {
cBaseFunction.call( this, "SUBTOTAL" );
this.setArgumentsMin( 1 );
this.setArgumentsMax( 255 );
}
function cSUBTOTAL() {
cBaseFunction.call(this, "SUBTOTAL");
this.setArgumentsMin(1);
this.setArgumentsMax(255);
}
cSUBTOTAL.prototype = Object.create( cBaseFunction.prototype );
cSUBTOTAL.prototype.Calculate = function ( arg ) {
cSUBTOTAL.prototype = Object.create(cBaseFunction.prototype);
cSUBTOTAL.prototype.Calculate = function (arg) {
var f, arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
if (cElementType.cellsRange === arg0.type || cElementType.cellsRange3D === arg0.type) {
arg0 = arg0.cross(arguments[1].first);
}
arg0 = arg0.tocNumber();
if ( !(arg0 instanceof cNumber) )
if (cElementType.number !== arg0.type) {
return this.value = arg0;
}
arg0 = arg0.getValue();
switch ( arg0 ) {
switch (arg0) {
case cSubTotalFunctionType.includes.AVERAGE:
case cSubTotalFunctionType.excludes.AVERAGE:
this.value = (new AscCommonExcel.cAVERAGE()).Calculate(arg.slice(1));
......@@ -3873,19 +3874,14 @@ cSUBTOTAL.prototype.Calculate = function ( arg ) {
}
return this.value;
};
cSUBTOTAL.prototype.getInfo = function () {
};
cSUBTOTAL.prototype.getInfo = function () {
return {
name:this.name,
args:"( function-number , argument-list )"
name: this.name, args: "( function-number , argument-list )"
};
};
};
function cSUM() {
// cBaseFunction.call( this, "SUM" );
// this.setArgumentsMin( 1 );
// this.setArgumentsMax( 255 );
function cSUM() {
this.name = "SUM";
this.type = cElementType.func;
this.value = null;
......@@ -3893,62 +3889,57 @@ function cSUM() {
this.argumentsCurrent = 0;
this.argumentsMax = 255;
this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat:-2
def: -1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat: -2
};
this.numFormat = this.formatType.def;
}
}
cSUM.prototype = Object.create( cBaseFunction.prototype );
cSUM.prototype.Calculate = function ( arg ) {
var arg0 = new cNumber( 0 );
for ( var i = 0; i < arg.length; i++ ) {
if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ) {
var _arrVal = arg[i].getValue();
for ( var j = 0; j < _arrVal.length; j++ ) {
if ( !(_arrVal[j] instanceof cBool || _arrVal[j] instanceof cString) )
arg0 = _func[arg0.type][_arrVal[j].type]( arg0, _arrVal[j], "+" );
if ( arg0 instanceof cError )
return this.value = arg0;
cSUM.prototype = Object.create(cBaseFunction.prototype);
cSUM.prototype.Calculate = function (arg) {
var element, _arg, arg0 = new cNumber(0);
for (var i = 0; i < arg.length; i++) {
element = arg[i];
if (cElementType.cellsRange === element.type || cElementType.cellsRange3D === element) {
var _arrVal = element.getValue();
for (var j = 0; j < _arrVal.length; j++) {
if (cElementType.bool !== _arrVal[j].type && cElementType.string !== _arrVal[j].type) {
arg0 = _func[arg0.type][_arrVal[j].type](arg0, _arrVal[j], "+");
}
if (cElementType.error === arg0.type) {
return this.value = arg0;
}
else if ( arg[i] instanceof cRef || arg[i] instanceof cRef3D ) {
var _arg = arg[i].getValue();
if ( !(_arg instanceof cBool || _arg instanceof cString) )
arg0 = _func[arg0.type][_arg.type]( arg0, _arg, "+" );
}
else if ( arg[i] instanceof cArray ) {
arg[i].foreach(
function ( arrElem ) {
if ( !(arrElem instanceof cBool || arrElem instanceof cString || arrElem instanceof cEmpty) )
arg0 = _func[arg0.type][arrElem.type]( arg0, arrElem, "+" );
} else if (cElementType.cell === element.type || cElementType.cell3D === element.type) {
_arg = element.getValue();
if (cElementType.bool !== _arg.type && cElementType.string !== _arg.type) {
arg0 = _func[arg0.type][_arg.type](arg0, _arg, "+");
}
)
} else if (cElementType.array === element.type) {
element.foreach(function (arrElem) {
if (cElementType.bool !== arrElem.type && cElementType.string !== arrElem.type && cElementType.empty !== arrElem.type) {
arg0 = _func[arg0.type][arrElem.type](arg0, arrElem, "+");
}
else {
var _arg = arg[i].tocNumber();
arg0 = _func[arg0.type][_arg.type]( arg0, _arg, "+" );
})
} else {
_arg = element.tocNumber();
arg0 = _func[arg0.type][_arg.type](arg0, _arg, "+");
}
if ( arg0 instanceof cError )
if (cElementType.error === arg0.type) {
return this.value = arg0;
}
}
return this.value = arg0;
};
cSUM.prototype.getInfo = function () {
};
cSUM.prototype.getInfo = function () {
return {
name:this.name,
args:"( argument-list )"
name: this.name, args: "( argument-list )"
};
};
};
function cSUMIF() {
// cBaseFunction.call( this, "SUMIF" );
// this.setArgumentsMin( 2 );
// this.setArgumentsMax( 3 );
function cSUMIF() {
this.name = "SUMIF";
this.type = cElementType.func;
this.value = null;
......@@ -3956,100 +3947,98 @@ function cSUMIF() {
this.argumentsCurrent = 0;
this.argumentsMax = 3;
this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat:-2
def: -1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat: -2
};
this.numFormat = this.formatType.def;
this.operatorRE = new RegExp( "^ *[<=> ]+ *" );
this.operatorRE = new RegExp("^ *[<=> ]+ *");
this.spaceRE = /\s/g;
}
}
cSUMIF.prototype = Object.create( cBaseFunction.prototype )
cSUMIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : arg[0], _sum = 0, valueForSearching, regexpSearch;
if ( !(arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea) ) {
if ( arg0 instanceof cArea3D ) {
cSUMIF.prototype = Object.create(cBaseFunction.prototype);
cSUMIF.prototype.Calculate = function (arg) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : arg[0], _sum = 0, valueForSearching;
if (cElementType.cell !== arg0.type && cElementType.cell3D !== arg0.type && cElementType.cellsRange !== arg0.type) {
if (cElementType.cellsRange3D === arg0.type) {
arg0 = arg0.tocArea();
if ( !arg0 )
return this.value = new cError( cErrorType.wrong_value_type );
if (!arg0) {
return this.value = new cError(cErrorType.wrong_value_type);
}
} else {
return this.value = new cError(cErrorType.wrong_value_type);
}
else
return this.value = new cError( cErrorType.wrong_value_type );
}
if ( !(arg2 instanceof cRef || arg2 instanceof cRef3D || arg2 instanceof cArea) ) {
if ( arg2 instanceof cArea3D ) {
if (cElementType.cell !== arg2.type && cElementType.cell3D !== arg2.type && cElementType.cellsRange !== arg2.type) {
if (cElementType.cellsRange3D === arg2.type) {
arg2 = arg2.tocArea();
if ( !arg2 )
return this.value = new cError( cErrorType.wrong_value_type );
if (!arg2) {
return this.value = new cError(cErrorType.wrong_value_type);
}
else
return this.value = new cError( cErrorType.wrong_value_type );
} else {
return this.value = new cError(cErrorType.wrong_value_type);
}
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
if (cElementType.cellsRange === arg1.type || cElementType.cellsRange3D === arg1.type) {
arg1 = arg1.cross(arguments[1].first);
} else if (arg1 instanceof cArray) {
arg1 = arg1.getElementRowCol(0, 0);
}
arg1 = arg1.tocString();
if ( !(arg1 instanceof cString) ) {
return this.value = new cError( cErrorType.wrong_value_type );
if (cElementType.string !== arg1.type) {
return this.value = new cError(cErrorType.wrong_value_type);
}
arg1 = arg1.toString();
var match = arg1.match( this.operatorRE ), search, oper, val;
if ( match ) {
search = arg1.substr( match[0].length );
oper = match[0].replace( this.spaceRE, "" );
}
else {
var match = arg1.match(this.operatorRE), search, oper, val;
if (match) {
search = arg1.substr(match[0].length);
oper = match[0].replace(this.spaceRE, "");
} else {
search = arg1;
}
valueForSearching = AscCommonExcel.parseNum( search ) ? new cNumber( search ) : new cString( search );
if ( arg0 instanceof cArea ) {
valueForSearching = AscCommonExcel.parseNum(search) ? new cNumber(search) : new cString(search);
if (cElementType.cellsRange === arg0.type) {
var arg0Matrix = arg0.getMatrix(), arg2Matrix = arg2.getMatrix(), valMatrix0, valMatrix2;
for ( var i = 0; i < arg0Matrix.length; i++ ) {
for ( var j = 0; j < arg0Matrix[i].length; j++ ) {
for (var i = 0; i < arg0Matrix.length; i++) {
for (var j = 0; j < arg0Matrix[i].length; j++) {
valMatrix0 = arg0Matrix[i][j];
valMatrix2 = arg2Matrix[i]? (arg2Matrix[i][j] ? arg2Matrix[i][j] : new cEmpty()) : new cEmpty();
if ( AscCommonExcel.matching( valMatrix0, valueForSearching, oper ) ) {
if ( valMatrix2 instanceof cNumber ) {
valMatrix2 = arg2Matrix[i] ? (arg2Matrix[i][j] ? arg2Matrix[i][j] : new cEmpty()) : new cEmpty();
if (AscCommonExcel.matching(valMatrix0, valueForSearching, oper)) {
if (cElementType.number === valMatrix2.type) {
_sum += valMatrix2.getValue();
}
}
}
}
}
else {
} else {
val = arg0.getValue();
if ( AscCommonExcel.matching( val, valueForSearching, oper ) ) {
var r = arg0.getRange(), ws = arg0.getWS(),
r1 = r.first.getRow0() + 0, c1 = arg2.getRange().first.getCol0();
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
if ( r.getValue() instanceof cNumber ) {
if (AscCommonExcel.matching(val, valueForSearching, oper)) {
var r = arg0.getRange(), ws = arg0.getWS(), r1 = r.first.getRow0() + 0, c1 = arg2.getRange().first
.getCol0();
r = new cRef(ws.getRange3(r1, c1, r1, c1).getName(), ws);
if (cElementType.number === r.getValue().type) {
_sum += r.getValue().getValue();
}
}
}
return this.value = new cNumber( _sum );
}
cSUMIF.prototype.getInfo = function () {
return this.value = new cNumber(_sum);
};
cSUMIF.prototype.getInfo = function () {
return {
name:this.name,
args:"( cell-range, selection-criteria [ , sum-range ] )"
name: this.name, args: "( cell-range, selection-criteria [ , sum-range ] )"
};
};
}
function cSUMIFS() {
cBaseFunction.call( this, "SUMIFS" );
}
function cSUMIFS() {
cBaseFunction.call(this, "SUMIFS");
}
cSUMIFS.prototype = Object.create( cBaseFunction.prototype )
cSUMIFS.prototype = Object.create(cBaseFunction.prototype);
function cSUMPRODUCT() {
// cBaseFunction.call( this, "SUMPRODUCT" );
......@@ -4070,7 +4059,7 @@ function cSUMPRODUCT() {
}
cSUMPRODUCT.prototype = Object.create( cBaseFunction.prototype )
cSUMPRODUCT.prototype = Object.create( cBaseFunction.prototype );
cSUMPRODUCT.prototype.Calculate = function ( arg ) {
var arg0 = new cNumber( 0 ), resArr = [], col = 0, row = 0, res = 1, _res = [];
......@@ -4128,13 +4117,13 @@ cSUMPRODUCT.prototype.Calculate = function ( arg ) {
res += _res[i]
return this.value = new cNumber( res );
}
};
cSUMPRODUCT.prototype.getInfo = function () {
return {
name:this.name,
args:"( argument-list )"
};
}
};
function cSUMSQ() {
// cBaseFunction.call( this, "SUMSQ" );
......@@ -4155,7 +4144,7 @@ function cSUMSQ() {
}
cSUMSQ.prototype = Object.create( cBaseFunction.prototype )
cSUMSQ.prototype = Object.create( cBaseFunction.prototype );
cSUMSQ.prototype.Calculate = function ( arg ) {
var arg0 = new cNumber( 0 );
......@@ -4197,13 +4186,13 @@ cSUMSQ.prototype.Calculate = function ( arg ) {
}
return this.value = arg0;
}
};
cSUMSQ.prototype.getInfo = function () {
return {
name:this.name,
args:"( argument-list )"
};
}
};
function cSUMX2MY2() {
// cBaseFunction.call( this, "SUMX2MY2" );
......@@ -4224,7 +4213,7 @@ function cSUMX2MY2() {
}
cSUMX2MY2.prototype = Object.create( cBaseFunction.prototype )
cSUMX2MY2.prototype = Object.create( cBaseFunction.prototype );
cSUMX2MY2.prototype.Calculate = function ( arg ) {
function sumX2MY2( a, b, _3d ) {
......@@ -4295,13 +4284,13 @@ cSUMX2MY2.prototype.Calculate = function ( arg ) {
return this.value = new cError( cErrorType.wrong_value_type );
return this.value = sumX2MY2( arg0, arg1, false );
}
};
cSUMX2MY2.prototype.getInfo = function () {
return {
name:this.name,
args:"( array-1 , array-2 )"
};
}
};
function cSUMX2PY2() {
// cBaseFunction.call( this, "SUMX2PY2" );
......@@ -4322,7 +4311,7 @@ function cSUMX2PY2() {
}
cSUMX2PY2.prototype = Object.create( cBaseFunction.prototype )
cSUMX2PY2.prototype = Object.create( cBaseFunction.prototype );
cSUMX2PY2.prototype.Calculate = function ( arg ) {
function sumX2MY2( a, b, _3d ) {
......@@ -4393,13 +4382,13 @@ cSUMX2PY2.prototype.Calculate = function ( arg ) {
return this.value = new cError( cErrorType.wrong_value_type );
return this.value = sumX2MY2( arg0, arg1, false );
}
};
cSUMX2PY2.prototype.getInfo = function () {
return {
name:this.name,
args:"( array-1 , array-2 )"
};
}
};
function cSUMXMY2() {
// cBaseFunction.call( this, "SUMXMY2" );
......@@ -4420,7 +4409,7 @@ function cSUMXMY2() {
}
cSUMXMY2.prototype = Object.create( cBaseFunction.prototype )
cSUMXMY2.prototype = Object.create( cBaseFunction.prototype );
cSUMXMY2.prototype.Calculate = function ( arg ) {
function sumX2MY2( a, b, _3d ) {
......@@ -4491,13 +4480,13 @@ cSUMXMY2.prototype.Calculate = function ( arg ) {
return this.value = new cError( cErrorType.wrong_value_type );
return this.value = sumX2MY2( arg0, arg1, false );
}
};
cSUMXMY2.prototype.getInfo = function () {
return {
name:this.name,
args:"( array-1 , array-2 )"
};
}
};
function cTAN() {
// cBaseFunction.call( this, "TAN" );
......@@ -4518,7 +4507,7 @@ function cTAN() {
}
cTAN.prototype = Object.create( cBaseFunction.prototype )
cTAN.prototype = Object.create( cBaseFunction.prototype );
cTAN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
......@@ -4543,13 +4532,13 @@ cTAN.prototype.Calculate = function ( arg ) {
return this.value = isNaN( a ) ? new cError( cErrorType.not_numeric ) : new cNumber( a );
}
return this.value = arg0;
}
};
cTAN.prototype.getInfo = function () {
return {
name:this.name,
args:"( x )"
};
}
};
function cTANH() {
// cBaseFunction.call( this, "TANH" );
......@@ -4570,7 +4559,7 @@ function cTANH() {
}
cTANH.prototype = Object.create( cBaseFunction.prototype )
cTANH.prototype = Object.create( cBaseFunction.prototype );
cTANH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
......@@ -4595,13 +4584,13 @@ cTANH.prototype.Calculate = function ( arg ) {
return this.value = isNaN( a ) ? new cError( cErrorType.not_numeric ) : new cNumber( a );
}
return this.value = arg0;
}
};
cTANH.prototype.getInfo = function () {
return {
name:this.name,
args:"( x )"
};
}
};
function cTRUNC() {
// cBaseFunction.call(this, "TRUNC" );
......@@ -4622,7 +4611,7 @@ function cTRUNC() {
}
cTRUNC.prototype = Object.create( cBaseFunction.prototype )
cTRUNC.prototype = Object.create( cBaseFunction.prototype );
cTRUNC.prototype.Calculate = function ( arg ) {
function truncHelper( a, b ) {
......@@ -4705,11 +4694,11 @@ cTRUNC.prototype.Calculate = function ( arg ) {
}
return this.value = truncHelper( arg0.getValue(), arg1.getValue() );
}
};
cTRUNC.prototype.getInfo = function () {
return {
name:this.name,
args:"( x [ , number-digits ] )"
};
}
};
})(window);
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