Commit 2d7238f3 authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix bug 20834

parent 86139e1b
......@@ -5275,44 +5275,53 @@ function parseNum( str ) {
return !isNaN( str );
}
function matching( x, y, oper ) {
var res = false, rS;
if ( y instanceof cString ) {
rS = searchRegExp2( x.value, y.toString() );
switch ( oper ) {
case "<>":
res = !rS;
break;
case "=":
default:
res = rS;
break;
}
} else if (typeof x === typeof y) {
switch ( oper ) {
case "<>":
res = (x.value != y.value);
break;
case ">":
res = (x.value > y.value);
break;
case "<":
res = (x.value < y.value);
break;
case ">=":
res = (x.value >= y.value);
break;
case "<=":
res = (x.value <= y.value);
break;
case "=":
default:
res = (x.value == y.value);
break;
}
}
return res;
}
function matching(x, y, operator) {
var res = false, rS;
if (cElementType.string === y.type) {
y = y.toString();
if ('' === y) {
// Empty compare string
rS = (cElementType.empty === x.type);
} else {
// Equal only string values
rS = (cElementType.string === x.type) ? searchRegExp2(x.value, y) : false;
}
switch (operator) {
case "<>":
res = !rS;
break;
case "=":
default:
res = rS;
break;
}
} else {
rS = (x.type === y.type);
switch (operator) {
case "<>":
res = !rS || (x.value != y.value);
break;
case ">":
res = rS && (x.value > y.value);
break;
case "<":
res = rS && (x.value < y.value);
break;
case ">=":
res = rS && (x.value >= y.value);
break;
case "<=":
res = rS && (x.value <= y.value);
break;
case "=":
default:
res = (x.value == y.value);
break;
}
}
return res;
}
function GetDiffDate360( nDay1, nMonth1, nYear1, nDay2, nMonth2, nYear2, bUSAMethod ) {
var nDayDiff;
......
......@@ -1145,81 +1145,71 @@ cCOUNTBLANK.prototype.getInfo = function () {
};
};
function cCOUNTIF() {
// cBaseFunction.call( this, "COUNTIF" );
// this.setArgumentsMin( 2 );
// this.setArgumentsMax( 2 );
this.name = "COUNTIF";
this.type = cElementType.func;
this.value = null;
this.argumentsMin = 2;
this.argumentsCurrent = 0;
this.argumentsMax = 2;
this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat:-2
};
this.numFormat = this.formatType.def;
}
function cCOUNTIF() {
this.name = "COUNTIF";
this.type = cElementType.func;
this.value = null;
this.argumentsMin = 2;
this.argumentsCurrent = 0;
this.argumentsMax = 2;
this.formatType = {
def: -1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat: -2
};
this.numFormat = this.formatType.def;
cCOUNTIF.prototype = Object.create( cBaseFunction.prototype );
cCOUNTIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], _count = 0, valueForSearching;
if ( !(arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea || arg0 instanceof cArea3D) ) {
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 );
}
cCOUNTIF.prototype = Object.create(cBaseFunction.prototype);
cCOUNTIF.prototype.Calculate = function (arg) {
var arg0 = arg[0], arg1 = arg[1], _count = 0, valueForSearching;
if (!(arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea || arg0 instanceof cArea3D)) {
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);
}
arg1 = arg1.tocString();
arg1 = arg1.tocString();
if ( !(arg1 instanceof cString) ) {
return this.value = new cError( cErrorType.wrong_value_type );
}
if (!(arg1 instanceof cString)) {
return this.value = new cError(cErrorType.wrong_value_type);
}
arg1 = arg1.toString();
var operators = new RegExp( "^ *[<=> ]+ *" ), search, oper, val,
match = arg1.match( operators );
arg1 = arg1.toString();
var operators = new RegExp("^ *[<=> ]+ *"), search, oper, val, match = arg1.match(operators);
if ( match ) {
search = arg1.substr( match[0].length );
oper = match[0].replace( /\s/g, "" );
}
else {
search = arg1;
}
valueForSearching = parseNum( search ) ? new cNumber( search ) : new cString( search );
if ( arg0 instanceof cArea ) {
arg0.foreach2( function ( _val ) {
_count += matching( _val, valueForSearching, oper );
} )
}
else if ( arg0 instanceof cArea3D ) {
val = arg0.getValue();
for ( var i = 0; i < val.length; i++ ) {
_count += matching( val[i], valueForSearching, oper );
if (match) {
search = arg1.substr(match[0].length);
oper = match[0].replace(/\s/g, "");
} else {
search = arg1;
}
valueForSearching = parseNum(search) ? new cNumber(search) : new cString(search);
if (arg0 instanceof cArea) {
arg0.foreach2(function (_val) {
_count += matching(_val, valueForSearching, oper);
})
} else if (arg0 instanceof cArea3D) {
val = arg0.getValue();
for (var i = 0; i < val.length; i++) {
_count += matching(val[i], valueForSearching, oper);
}
} else {
val = arg0.getValue();
_count += matching(val, valueForSearching, oper);
}
}
else {
val = arg0.getValue();
_count += matching( val, valueForSearching, oper );
}
return this.value = new cNumber( _count );
};
cCOUNTIF.prototype.getInfo = function () {
return {
name:this.name,
args:"( cell-range, selection-criteria )"
return this.value = new cNumber(_count);
};
cCOUNTIF.prototype.getInfo = function () {
return {
name: this.name, args: "( cell-range, selection-criteria )"
};
};
};
function cCOUNTIFS() {
cBaseFunction.call( this, "COUNTIFS" );
......
This diff is collapsed.
......@@ -1277,8 +1277,7 @@
//TODO: add checks and error handling
//Get data type
var dataObject = JSON.parse(e.data);
var type = dataObject['type'];
switch (type) {
switch (dataObject['type']) {
case 'auth' :
t._onAuth(dataObject);
break;
......@@ -1325,6 +1324,7 @@
break;
case 'license':
t._onLicense(dataObject);
break;
}
};
sockjs.onclose = function(evt) {
......
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