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

конфликт имен.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55742 954022d7-b5bf-4e40-9824-e11837661b57
parent dd2c6b3a
...@@ -22,6 +22,7 @@ var DayCountBasis = { ...@@ -22,6 +22,7 @@ var DayCountBasis = {
} }
function yearFrac(d1, d2, mode) { function yearFrac(d1, d2, mode) {
d1.truncate(); d1.truncate();
d2.truncate(); d2.truncate();
...@@ -34,7 +35,7 @@ function yearFrac(d1, d2, mode) { ...@@ -34,7 +35,7 @@ function yearFrac(d1, d2, mode) {
switch ( mode ) { switch ( mode ) {
case DayCountBasis.UsPsa30_360: case DayCountBasis.UsPsa30_360:
return new CNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) ) / 360 ); return new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) ) / 360 );
case DayCountBasis.ActualActual: case DayCountBasis.ActualActual:
var yc = /*Math.abs*/( year2 - year1 ), var yc = /*Math.abs*/( year2 - year1 ),
sd = year1 > year2 ? new Date(d2) : new Date(d1), sd = year1 > year2 ? new Date(d2) : new Date(d1),
...@@ -45,19 +46,19 @@ function yearFrac(d1, d2, mode) { ...@@ -45,19 +46,19 @@ function yearFrac(d1, d2, mode) {
} }
yearAverage /= (yc + 1); yearAverage /= (yc + 1);
dayDiff /= (yearAverage * c_msPerDay); dayDiff /= (yearAverage * c_msPerDay);
return new CNumber( dayDiff ); return new cNumber( dayDiff );
case DayCountBasis.Actual360: case DayCountBasis.Actual360:
var dayDiff = Math.abs( d2 - d1 ); var dayDiff = Math.abs( d2 - d1 );
dayDiff /= (360 * c_msPerDay); dayDiff /= (360 * c_msPerDay);
return new CNumber( dayDiff ); return new cNumber( dayDiff );
case DayCountBasis.Actual365: case DayCountBasis.Actual365:
var dayDiff = Math.abs( d2 - d1 ); var dayDiff = Math.abs( d2 - d1 );
dayDiff /= (365 * c_msPerDay); dayDiff /= (365 * c_msPerDay);
return new CNumber( dayDiff ); return new cNumber( dayDiff );
case DayCountBasis.Europ30_360: case DayCountBasis.Europ30_360:
return new CNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, false ) ) / 360 ); return new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, false ) ) / 360 );
default: default:
return new CError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
} }
} }
...@@ -71,7 +72,7 @@ function diffDate(d1, d2, mode){ ...@@ -71,7 +72,7 @@ function diffDate(d1, d2, mode){
switch ( mode ) { switch ( mode ) {
case DayCountBasis.UsPsa30_360: case DayCountBasis.UsPsa30_360:
return new CNumber( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) ); return new cNumber( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) );
case DayCountBasis.ActualActual: case DayCountBasis.ActualActual:
var yc = /*Math.abs*/( year2 - year1 ), var yc = /*Math.abs*/( year2 - year1 ),
sd = year1 > year2 ? new Date(d2) : new Date(d1), sd = year1 > year2 ? new Date(d2) : new Date(d1),
...@@ -82,19 +83,19 @@ function diffDate(d1, d2, mode){ ...@@ -82,19 +83,19 @@ function diffDate(d1, d2, mode){
} }
yearAverage /= (yc + 1); yearAverage /= (yc + 1);
dayDiff /= c_msPerDay; dayDiff /= c_msPerDay;
return new CNumber( dayDiff ); return new cNumber( dayDiff );
case DayCountBasis.Actual360: case DayCountBasis.Actual360:
var dayDiff = d2 - d1; var dayDiff = d2 - d1;
dayDiff /= c_msPerDay; dayDiff /= c_msPerDay;
return new CNumber( dayDiff ); return new cNumber( dayDiff );
case DayCountBasis.Actual365: case DayCountBasis.Actual365:
var dayDiff = d2 - d1; var dayDiff = d2 - d1;
dayDiff /= c_msPerDay; dayDiff /= c_msPerDay;
return new CNumber( dayDiff ); return new cNumber( dayDiff );
case DayCountBasis.Europ30_360: case DayCountBasis.Europ30_360:
return new CNumber( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, false ) ); return new cNumber( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, false ) );
default: default:
return new CError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
} }
} }
...@@ -113,7 +114,7 @@ function diffDate2(d1, d2, mode){ ...@@ -113,7 +114,7 @@ function diffDate2(d1, d2, mode){
nDaysInYear = 360; nDaysInYear = 360;
nYears = year1 - year2; nYears = year1 - year2;
nDayDiff = Math.abs( GetDiffDate360( date1, month1+1, year1, d1.isLeapYear(), date2, month2+1, year2, true ) ) - nYears * nDaysInYear; nDayDiff = Math.abs( GetDiffDate360( date1, month1+1, year1, d1.isLeapYear(), date2, month2+1, year2, true ) ) - nYears * nDaysInYear;
return new CNumber( nYears + nDayDiff / nDaysInYear ); return new cNumber( nYears + nDayDiff / nDaysInYear );
case DayCountBasis.ActualActual: case DayCountBasis.ActualActual:
nYears = year2 - year1; nYears = year2 - year1;
nDaysInYear = d1.isLeapYear() ? 366 : 365; nDaysInYear = d1.isLeapYear() ? 366 : 365;
...@@ -130,26 +131,26 @@ function diffDate2(d1, d2, mode){ ...@@ -130,26 +131,26 @@ function diffDate2(d1, d2, mode){
if( dayDiff < 0 ) if( dayDiff < 0 )
dayDiff += nDaysInYear; dayDiff += nDaysInYear;
return new CNumber( nYears + dayDiff / nDaysInYear ); return new cNumber( nYears + dayDiff / nDaysInYear );
case DayCountBasis.Actual360: case DayCountBasis.Actual360:
nDaysInYear = 360; nDaysInYear = 360;
nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear ); nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear );
nDayDiff = (d2 - d1)/c_msPerDay; nDayDiff = (d2 - d1)/c_msPerDay;
nDayDiff %= nDaysInYear; nDayDiff %= nDaysInYear;
return new CNumber( nYears + nDayDiff / nDaysInYear ); return new cNumber( nYears + nDayDiff / nDaysInYear );
case DayCountBasis.Actual365: case DayCountBasis.Actual365:
nDaysInYear = 365; nDaysInYear = 365;
nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear ); nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear );
nDayDiff = (d2 - d1)/c_msPerDay; nDayDiff = (d2 - d1)/c_msPerDay;
nDayDiff %= nDaysInYear; nDayDiff %= nDaysInYear;
return new CNumber( nYears + nDayDiff / nDaysInYear ); return new cNumber( nYears + nDayDiff / nDaysInYear );
case DayCountBasis.Europ30_360: case DayCountBasis.Europ30_360:
nDaysInYear = 360; nDaysInYear = 360;
nYears = year1 - year2; nYears = year1 - year2;
nDayDiff = Math.abs( GetDiffDate360( date1, month1+1, year1, d1.isLeapYear(), date2, month2+1, year2, false ) ) - nYears * nDaysInYear; nDayDiff = Math.abs( GetDiffDate360( date1, month1+1, year1, d1.isLeapYear(), date2, month2+1, year2, false ) ) - nYears * nDaysInYear;
return new CNumber( nYears + nDayDiff / nDaysInYear ); return new cNumber( nYears + nDayDiff / nDaysInYear );
default: default:
return new CError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
} }
} }
...@@ -258,22 +259,22 @@ cDATE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -258,22 +259,22 @@ cDATE.prototype = Object.create( cBaseFunction.prototype )
cDATE.prototype.Calculate = function ( arg ) { cDATE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], year, month, day; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], year, month, day;
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 ); arg1 = arg1.getElement( 0 );
} }
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
else if ( arg2 instanceof CArray ) { else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement( 0 ); arg2 = arg2.getElement( 0 );
} }
...@@ -281,9 +282,9 @@ cDATE.prototype.Calculate = function ( arg ) { ...@@ -281,9 +282,9 @@ cDATE.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg0 instanceof CError ) return this.setCA( arg0, true ); if ( arg0 instanceof cError ) return this.setCA( arg0, true );
if ( arg1 instanceof CError ) return this.setCA( arg1, true ); if ( arg1 instanceof cError ) return this.setCA( arg1, true );
if ( arg2 instanceof CError ) return this.setCA( arg2, true ); if ( arg2 instanceof cError ) return this.setCA( arg2, true );
year = arg0.getValue(); year = arg0.getValue();
month = arg1.getValue(); month = arg1.getValue();
...@@ -292,9 +293,9 @@ cDATE.prototype.Calculate = function ( arg ) { ...@@ -292,9 +293,9 @@ cDATE.prototype.Calculate = function ( arg ) {
if ( year >= 0 && year <= 1899 ) if ( year >= 0 && year <= 1899 )
year += 1900; year += 1900;
if ( month == 0 ) { if ( month == 0 ) {
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
} }
this.value = new CNumber( Math.round( new Date( year, month - 1, day ).getExcelDate() ) ) this.value = new cNumber( Math.round( new Date( year, month - 1, day ).getExcelDate() ) )
this.value.numFormat = 14; this.value.numFormat = 14;
this.value.ca = true; this.value.ca = true;
return this.value; return this.value;
...@@ -328,24 +329,24 @@ function cDATEDIF() { ...@@ -328,24 +329,24 @@ function cDATEDIF() {
cDATEDIF.prototype = Object.create( cBaseFunction.prototype ) cDATEDIF.prototype = Object.create( cBaseFunction.prototype )
cDATEDIF.prototype.Calculate = function ( arg ) { cDATEDIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
else if ( arg2 instanceof CArray ) { else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElementRowCol( 0, 0 ); arg2 = arg2.getElementRowCol( 0, 0 );
} }
...@@ -353,14 +354,14 @@ cDATEDIF.prototype.Calculate = function ( arg ) { ...@@ -353,14 +354,14 @@ cDATEDIF.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocString(); arg2 = arg2.tocString();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof CError ) return this.value = arg2; if ( arg2 instanceof cError ) return this.value = arg2;
var val0 = arg0.getValue(), val1 = arg1.getValue(); var val0 = arg0.getValue(), val1 = arg1.getValue();
if ( val0 < 0 || val1 < 0 || val0 >= val1 ) if ( val0 < 0 || val1 < 0 || val0 >= val1 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
val0 = Date.prototype.getDateFromExcel( val0 ); val0 = Date.prototype.getDateFromExcel( val0 );
val1 = Date.prototype.getDateFromExcel( val1 ); val1 = Date.prototype.getDateFromExcel( val1 );
...@@ -379,38 +380,38 @@ cDATEDIF.prototype.Calculate = function ( arg ) { ...@@ -379,38 +380,38 @@ cDATEDIF.prototype.Calculate = function ( arg ) {
switch ( arg2.getValue().toUpperCase() ) { switch ( arg2.getValue().toUpperCase() ) {
case "Y": case "Y":
return this.value = new CNumber( dateDiff( val0, val1 )[0] ); return this.value = new cNumber( dateDiff( val0, val1 )[0] );
break; break;
case "M": case "M":
return this.value = new CNumber( dateDiff( val0, val1 )[1] ); return this.value = new cNumber( dateDiff( val0, val1 )[1] );
break; break;
case "D": case "D":
return this.value = new CNumber( parseInt( (val1 - val0) / c_msPerDay ) ); return this.value = new cNumber( parseInt( (val1 - val0) / c_msPerDay ) );
break; break;
case "MD": case "MD":
if ( val0.getDate() > val1.getDate() ) { if ( val0.getDate() > val1.getDate() ) {
this.value = new CNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear(), val0.getMonth() + 1, val1.getDate() ) ) / c_msPerDay ); this.value = new cNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear(), val0.getMonth() + 1, val1.getDate() ) ) / c_msPerDay );
} }
else { else {
this.value = new CNumber( val1.getDate() - val0.getDate() ); this.value = new cNumber( val1.getDate() - val0.getDate() );
} }
return this.value; return this.value;
break; break;
case "YM": case "YM":
var d = dateDiff( val0, val1 ); var d = dateDiff( val0, val1 );
return this.value = new CNumber( d[1] - d[0] * 12 ); return this.value = new cNumber( d[1] - d[0] * 12 );
break; break;
case "YD": case "YD":
if ( val0.getMonth() > val1.getMonth() ) { if ( val0.getMonth() > val1.getMonth() ) {
this.value = new CNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear() + 1, val1.getMonth(), val1.getDate() ) ) / c_msPerDay ); this.value = new cNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear() + 1, val1.getMonth(), val1.getDate() ) ) / c_msPerDay );
} }
else { else {
this.value = new CNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear(), val1.getMonth(), val1.getDate() ) ) / c_msPerDay ); this.value = new cNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear(), val1.getMonth(), val1.getDate() ) ) / c_msPerDay );
} }
return this.value; return this.value;
break; break;
default: default:
return this.value = new CError( cErrorType.not_numeric ) return this.value = new cError( cErrorType.not_numeric )
} }
} }
...@@ -444,27 +445,27 @@ cDATEVALUE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -444,27 +445,27 @@ cDATEVALUE.prototype = Object.create( cBaseFunction.prototype )
cDATEVALUE.prototype.Calculate = function ( arg ) { cDATEVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if ( arg0.tocNumber() instanceof CNumber && arg0.tocNumber().getValue() > 0 ) if ( arg0.tocNumber() instanceof cNumber && arg0.tocNumber().getValue() > 0 )
return this.value = new CNumber( parseInt( arg0.tocNumber().getValue() ) ); return this.value = new cNumber( parseInt( arg0.tocNumber().getValue() ) );
var res = g_oFormatParser.parse( arg0.getValue() ); var res = g_oFormatParser.parse( arg0.getValue() );
if ( res && res.bDateTime ) if ( res && res.bDateTime )
return this.value = new CNumber( parseInt( res.value ) ); return this.value = new cNumber( parseInt( res.value ) );
else else
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
cDATEVALUE.prototype.getInfo = function () { cDATEVALUE.prototype.getInfo = function () {
return { return {
...@@ -495,32 +496,32 @@ function cDAY() { ...@@ -495,32 +496,32 @@ function cDAY() {
cDAY.prototype = Object.create( cBaseFunction.prototype ) cDAY.prototype = Object.create( cBaseFunction.prototype )
cDAY.prototype.Calculate = function ( arg ) { cDAY.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
if ( arg0 instanceof CError ) return this.setCA( arg0, true ); if ( arg0 instanceof cError ) return this.setCA( arg0, true );
else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) { else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
val = arg0.getValue().tocNumber(); val = arg0.getValue().tocNumber();
if ( val instanceof CNumber || val instanceof CBool ) { if ( val instanceof cNumber || val instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof CString ) { else if ( arg0 instanceof cString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof CError || val instanceof CEmpty ) { if ( val instanceof cError || val instanceof cEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
else else
val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) ); val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
...@@ -530,17 +531,17 @@ cDAY.prototype.Calculate = function ( arg ) { ...@@ -530,17 +531,17 @@ cDAY.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val < 60 ) if ( val < 60 )
return this.setCA( new CNumber( ( new Date( (val - c_DateCorrectConst) * c_msPerDay ) ).getUTCDate() ), true, 0 ); return this.setCA( new cNumber( ( new Date( (val - c_DateCorrectConst) * c_msPerDay ) ).getUTCDate() ), true, 0 );
else if ( val == 60 ) else if ( val == 60 )
return this.setCA( new CNumber( ( new Date( (val - c_DateCorrectConst - 1) * c_msPerDay ) ).getUTCDate() + 1 ), true, 0 ); return this.setCA( new cNumber( ( new Date( (val - c_DateCorrectConst - 1) * c_msPerDay ) ).getUTCDate() + 1 ), true, 0 );
else else
return this.setCA( new CNumber( ( new Date( (val - c_DateCorrectConst - 1) * c_msPerDay ) ).getUTCDate() ), true, 0 ); return this.setCA( new cNumber( ( new Date( (val - c_DateCorrectConst - 1) * c_msPerDay ) ).getUTCDate() ), true, 0 );
} }
else else
return this.setCA( new CNumber( ( new Date( (val - c_DateCorrectConst) * c_msPerDay ) ).getUTCDate() ), true, 0 ); return this.setCA( new cNumber( ( new Date( (val - c_DateCorrectConst) * c_msPerDay ) ).getUTCDate() ), true, 0 );
} }
cDAY.prototype.getInfo = function () { cDAY.prototype.getInfo = function () {
return { return {
...@@ -570,26 +571,26 @@ function cDAYS360() { ...@@ -570,26 +571,26 @@ function cDAYS360() {
} }
cDAYS360.prototype = Object.create( cBaseFunction.prototype ) cDAYS360.prototype = Object.create( cBaseFunction.prototype )
cDAYS360.prototype.Calculate = function ( arg ) { cDAYS360.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new CBool( false ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cBool( false );
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
else if ( arg2 instanceof CArray ) { else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElementRowCol( 0, 0 ); arg2 = arg2.getElementRowCol( 0, 0 );
} }
...@@ -597,16 +598,16 @@ cDAYS360.prototype.Calculate = function ( arg ) { ...@@ -597,16 +598,16 @@ cDAYS360.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocBool(); arg2 = arg2.tocBool();
if ( arg0 instanceof CError )return this.value = arg0; if ( arg0 instanceof cError )return this.value = arg0;
if ( arg1 instanceof CError )return this.value = arg1; if ( arg1 instanceof cError )return this.value = arg1;
if ( arg2 instanceof CError )return this.value = arg2; if ( arg2 instanceof cError )return this.value = arg2;
if ( arg0.getValue() < 0 )return this.value = new CError( cErrorType.not_numeric ); if ( arg0.getValue() < 0 )return this.value = new cError( cErrorType.not_numeric );
if ( arg1.getValue() < 0 )return this.value = new CError( cErrorType.not_numeric ); if ( arg1.getValue() < 0 )return this.value = new cError( cErrorType.not_numeric );
var date1 = Date.prototype.getDateFromExcel( arg0.getValue() ), date2 = Date.prototype.getDateFromExcel( arg1.getValue() ); var date1 = Date.prototype.getDateFromExcel( arg0.getValue() ), date2 = Date.prototype.getDateFromExcel( arg1.getValue() );
return this.value = new CNumber( GetDiffDate360( date1.getDate(), date1.getMonth() + 1, date1.getFullYear(), date1.isLeapYear(), return this.value = new cNumber( GetDiffDate360( date1.getDate(), date1.getMonth() + 1, date1.getFullYear(), date1.isLeapYear(),
date2.getDate(), date2.getMonth() + 1, date2.getFullYear(), !arg2.toBool() ) ) date2.getDate(), date2.getMonth() + 1, date2.getFullYear(), !arg2.toBool() ) )
} }
...@@ -640,30 +641,30 @@ cEDATE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -640,30 +641,30 @@ cEDATE.prototype = Object.create( cBaseFunction.prototype )
cEDATE.prototype.Calculate = function ( arg ) { cEDATE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
var val = arg0.getValue(), date, _date; var val = arg0.getValue(), date, _date;
if ( val < 0 ) if ( val < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val < 60 ) if ( val < 60 )
val = new Date( (val - c_DateCorrectConst) * c_msPerDay ); val = new Date( (val - c_DateCorrectConst) * c_msPerDay );
...@@ -689,7 +690,7 @@ cEDATE.prototype.Calculate = function ( arg ) { ...@@ -689,7 +690,7 @@ cEDATE.prototype.Calculate = function ( arg ) {
val = new Date( val.setMonth( val.getMonth() + arg1.getValue() ) ); val = new Date( val.setMonth( val.getMonth() + arg1.getValue() ) );
} }
return this.value = new CNumber( Math.floor( ( val.getTime() / 1000 - val.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) ) return this.value = new cNumber( Math.floor( ( val.getTime() / 1000 - val.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) )
} }
cEDATE.prototype.getInfo = function () { cEDATE.prototype.getInfo = function () {
return { return {
...@@ -721,30 +722,30 @@ cEOMONTH.prototype = Object.create( cBaseFunction.prototype ) ...@@ -721,30 +722,30 @@ cEOMONTH.prototype = Object.create( cBaseFunction.prototype )
cEOMONTH.prototype.Calculate = function ( arg ) { cEOMONTH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
var val = arg0.getValue(), date, _date; var val = arg0.getValue(), date, _date;
if ( val < 0 ) if ( val < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val < 60 ) if ( val < 60 )
val = new Date( (val - c_DateCorrectConst) * c_msPerDay ); val = new Date( (val - c_DateCorrectConst) * c_msPerDay );
...@@ -762,7 +763,7 @@ cEOMONTH.prototype.Calculate = function ( arg ) { ...@@ -762,7 +763,7 @@ cEOMONTH.prototype.Calculate = function ( arg ) {
val.setMonth( val.getMonth() + arg1.getValue() ); val.setMonth( val.getMonth() + arg1.getValue() );
val.setDate( val.getDaysInMonth() ); val.setDate( val.getDaysInMonth() );
return this.value = new CNumber( Math.floor( ( val.getTime() / 1000 - val.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) ); return this.value = new cNumber( Math.floor( ( val.getTime() / 1000 - val.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) );
} }
cEOMONTH.prototype.getInfo = function () { cEOMONTH.prototype.getInfo = function () {
return { return {
...@@ -793,35 +794,35 @@ function cHOUR() { ...@@ -793,35 +794,35 @@ function cHOUR() {
cHOUR.prototype = Object.create( cBaseFunction.prototype ) cHOUR.prototype = Object.create( cBaseFunction.prototype )
cHOUR.prototype.Calculate = function ( arg ) { cHOUR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof CError )return this.setCA( arg0, true ); if ( arg0 instanceof cError )return this.setCA( arg0, true );
else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) { else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof CError )return this.setCA( val, true ); if ( val instanceof cError )return this.setCA( val, true );
else if ( val instanceof CNumber || val instanceof CBool ) { else if ( val instanceof cNumber || val instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof CString ) { else if ( arg0 instanceof cString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof CError || val instanceof CEmpty ) { if ( val instanceof cError || val instanceof cEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
d = g_oFormatParser.parseDate( arg0.getValue() ); d = g_oFormatParser.parseDate( arg0.getValue() );
if ( d == null ) { if ( d == null ) {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
val = d.value; val = d.value;
} }
...@@ -833,9 +834,9 @@ cHOUR.prototype.Calculate = function ( arg ) { ...@@ -833,9 +834,9 @@ cHOUR.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
else //1 2 3 4 4 3 2 1 else //1 2 3 4 4 3 2 1
return this.setCA( new CNumber( parseInt( ( ( val - Math.floor( val ) ) * 24 ).toFixed( cExcelDateTimeDigits ) ) ), true, 0 ); return this.setCA( new cNumber( parseInt( ( ( val - Math.floor( val ) ) * 24 ).toFixed( cExcelDateTimeDigits ) ) ), true, 0 );
} }
cHOUR.prototype.getInfo = function () { cHOUR.prototype.getInfo = function () {
return { return {
...@@ -866,35 +867,35 @@ function cMINUTE() { ...@@ -866,35 +867,35 @@ function cMINUTE() {
cMINUTE.prototype = Object.create( cBaseFunction.prototype ) cMINUTE.prototype = Object.create( cBaseFunction.prototype )
cMINUTE.prototype.Calculate = function ( arg ) { cMINUTE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof CError ) return this.setCA( arg0, true ); if ( arg0 instanceof cError ) return this.setCA( arg0, true );
else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) { else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof CError ) return this.setCA( val, true ); if ( val instanceof cError ) return this.setCA( val, true );
else if ( val instanceof CNumber || val instanceof CBool ) { else if ( val instanceof cNumber || val instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof CString ) { else if ( arg0 instanceof cString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof CError || val instanceof CEmpty ) { if ( val instanceof cError || val instanceof cEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
d = g_oFormatParser.parseDate( arg0.getValue() ); d = g_oFormatParser.parseDate( arg0.getValue() );
if ( d == null ) { if ( d == null ) {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
val = d.value; val = d.value;
} }
...@@ -906,10 +907,10 @@ cMINUTE.prototype.Calculate = function ( arg ) { ...@@ -906,10 +907,10 @@ cMINUTE.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
else { else {
val = parseInt( ( ( val * 24 - Math.floor( val * 24 ) ) * 60 ).toFixed( cExcelDateTimeDigits ) ) % 60; val = parseInt( ( ( val * 24 - Math.floor( val * 24 ) ) * 60 ).toFixed( cExcelDateTimeDigits ) ) % 60;
return this.setCA( new CNumber( val ), true, 0 ); return this.setCA( new cNumber( val ), true, 0 );
} }
} }
cMINUTE.prototype.getInfo = function () { cMINUTE.prototype.getInfo = function () {
...@@ -941,33 +942,33 @@ function cMONTH() { ...@@ -941,33 +942,33 @@ function cMONTH() {
cMONTH.prototype = Object.create( cBaseFunction.prototype ) cMONTH.prototype = Object.create( cBaseFunction.prototype )
cMONTH.prototype.Calculate = function ( arg ) { cMONTH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof CError ) return this.setCA( arg0, true ); if ( arg0 instanceof cError ) return this.setCA( arg0, true );
else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) { else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof CError ) return this.setCA( val, true ); if ( val instanceof cError ) return this.setCA( val, true );
else if ( val instanceof CNumber || val instanceof CBool ) { else if ( val instanceof cNumber || val instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof CString ) { else if ( arg0 instanceof cString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof CError || val instanceof CEmpty ) { if ( val instanceof cError || val instanceof cEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
else else
val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) ); val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
...@@ -977,15 +978,15 @@ cMONTH.prototype.Calculate = function ( arg ) { ...@@ -977,15 +978,15 @@ cMONTH.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
if ( !g_bDate1904 ) { if ( !g_bDate1904 ) {
if ( val == 60 ) if ( val == 60 )
return this.setCA( new CNumber( 2 ), true, 0 ); return this.setCA( new cNumber( 2 ), true, 0 );
else else
return this.setCA( new CNumber( ( new Date( ( (val == 0 ? 1 : val) - c_DateCorrectConst - 1 ) * c_msPerDay ) ).getUTCMonth() + 1 ), true, 0 ); return this.setCA( new cNumber( ( new Date( ( (val == 0 ? 1 : val) - c_DateCorrectConst - 1 ) * c_msPerDay ) ).getUTCMonth() + 1 ), true, 0 );
} }
else else
return this.setCA( new CNumber( ( new Date( ( (val == 0 ? 1 : val) - c_DateCorrectConst ) * c_msPerDay ) ).getUTCMonth() + 1 ), true, 0 ); return this.setCA( new cNumber( ( new Date( ( (val == 0 ? 1 : val) - c_DateCorrectConst ) * c_msPerDay ) ).getUTCMonth() + 1 ), true, 0 );
} }
cMONTH.prototype.getInfo = function () { cMONTH.prototype.getInfo = function () {
return { return {
...@@ -1017,30 +1018,30 @@ cNETWORKDAYS.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1017,30 +1018,30 @@ cNETWORKDAYS.prototype = Object.create( cBaseFunction.prototype )
cNETWORKDAYS.prototype.Calculate = function ( arg ) { cNETWORKDAYS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = []; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = [];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
var val0 = arg0.getValue(), val1 = arg1.getValue(), dif, count = 0; var val0 = arg0.getValue(), val1 = arg1.getValue(), dif, count = 0;
if ( val0 < 0 ) if ( val0 < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val0 < 60 ) if ( val0 < 60 )
val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay ); val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay );
...@@ -1053,7 +1054,7 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) { ...@@ -1053,7 +1054,7 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) {
val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay ); val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay );
if ( val1 < 0 ) if ( val1 < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val1 < 60 ) if ( val1 < 60 )
val1 = new Date( (val1 - c_DateCorrectConst) * c_msPerDay ); val1 = new Date( (val1 - c_DateCorrectConst) * c_msPerDay );
...@@ -1068,29 +1069,29 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) { ...@@ -1068,29 +1069,29 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) {
var holidays = []; var holidays = [];
if ( arg2 ) { if ( arg2 ) {
if ( arg2 instanceof CRef ) { if ( arg2 instanceof cRef ) {
var a = arg2.getValue(); var a = arg2.getValue();
if ( a instanceof CNumber && a.getValue() >= 0 ) { if ( a instanceof cNumber && a.getValue() >= 0 ) {
holidays.push( a ); holidays.push( a );
} }
} }
else if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { else if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
var arr = arg2.getValue(); var arr = arg2.getValue();
for ( var i = 0; i < arr.length; i++ ) { for ( var i = 0; i < arr.length; i++ ) {
if ( arr[i] instanceof CNumber && arr[i].getValue() >= 0 ) { if ( arr[i] instanceof cNumber && arr[i].getValue() >= 0 ) {
holidays.push( arr[i] ); holidays.push( arr[i] );
} }
} }
} }
else if ( arg2 instanceof CArray ) { else if ( arg2 instanceof cArray ) {
arg2.foreach( function ( elem, r, c ) { arg2.foreach( function ( elem, r, c ) {
if ( elem instanceof CNumber ) { if ( elem instanceof cNumber ) {
holidays.push( elem ); holidays.push( elem );
} }
else if ( elem instanceof CString ) { else if ( elem instanceof cString ) {
var res = g_oFormatParser.parse( elem.getValue() ); var res = g_oFormatParser.parse( elem.getValue() );
if ( res && res.bDateTime && res.value >= 0 ) if ( res && res.bDateTime && res.value >= 0 )
holidays.push( new CNumber( parseInt( res.value ) ) ); holidays.push( new cNumber( parseInt( res.value ) ) );
} }
} ) } )
} }
...@@ -1116,7 +1117,7 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) { ...@@ -1116,7 +1117,7 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) {
if ( date.getDay() != 6 && date.getDay() != 0 && includeInHolidays( date ) ) if ( date.getDay() != 6 && date.getDay() != 0 && includeInHolidays( date ) )
count++; count++;
} }
return this.value = new CNumber( (dif < 0 ? -1 : 1) * count ); return this.value = new cNumber( (dif < 0 ? -1 : 1) * count );
} }
cNETWORKDAYS.prototype.getInfo = function () { cNETWORKDAYS.prototype.getInfo = function () {
return { return {
...@@ -1151,7 +1152,7 @@ function cNOW() { ...@@ -1151,7 +1152,7 @@ function cNOW() {
cNOW.prototype = Object.create( cBaseFunction.prototype ) cNOW.prototype = Object.create( cBaseFunction.prototype )
cNOW.prototype.Calculate = function () { cNOW.prototype.Calculate = function () {
var d = new Date(); var d = new Date();
this.value = new CNumber( Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) + ( (d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds()) / c_sPerDay ) ); this.value = new cNumber( Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) + ( (d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds()) / c_sPerDay ) );
this.value.numFormat = 22; this.value.numFormat = 22;
return this.setCA( this.value, true ); return this.setCA( this.value, true );
} }
...@@ -1184,35 +1185,35 @@ function cSECOND() { ...@@ -1184,35 +1185,35 @@ function cSECOND() {
cSECOND.prototype = Object.create( cBaseFunction.prototype ) cSECOND.prototype = Object.create( cBaseFunction.prototype )
cSECOND.prototype.Calculate = function ( arg ) { cSECOND.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof CError ) return this.setCA( arg0, true ); if ( arg0 instanceof cError ) return this.setCA( arg0, true );
else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) { else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof CError ) return this.setCA( val, true ); if ( val instanceof cError ) return this.setCA( val, true );
else if ( val instanceof CNumber || val instanceof CBool ) { else if ( val instanceof cNumber || val instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof CString ) { else if ( arg0 instanceof cString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof CError || val instanceof CEmpty ) { if ( val instanceof cError || val instanceof cEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
d = g_oFormatParser.parseDate( arg0.getValue() ); d = g_oFormatParser.parseDate( arg0.getValue() );
if ( d == null ) { if ( d == null ) {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
val = d.value; val = d.value;
} }
...@@ -1224,10 +1225,10 @@ cSECOND.prototype.Calculate = function ( arg ) { ...@@ -1224,10 +1225,10 @@ cSECOND.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
else { else {
val = parseInt( (( val * 24 * 60 - Math.floor( val * 24 * 60 ) ) * 60).toFixed( cExcelDateTimeDigits ) ) % 60; val = parseInt( (( val * 24 * 60 - Math.floor( val * 24 * 60 ) ) * 60).toFixed( cExcelDateTimeDigits ) ) % 60;
return this.setCA( new CNumber( val ), true, 0 ); return this.setCA( new cNumber( val ), true, 0 );
} }
} }
cSECOND.prototype.getInfo = function () { cSECOND.prototype.getInfo = function () {
...@@ -1259,22 +1260,22 @@ cTIME.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1259,22 +1260,22 @@ cTIME.prototype = Object.create( cBaseFunction.prototype )
cTIME.prototype.Calculate = function ( arg ) { cTIME.prototype.Calculate = function ( arg ) {
var hour = arg[0], minute = arg[1], second = arg[2]; var hour = arg[0], minute = arg[1], second = arg[2];
if ( hour instanceof CArea || hour instanceof CArea3D ) { if ( hour instanceof cArea || hour instanceof cArea3D ) {
hour = hour.cross( arguments[1].first ); hour = hour.cross( arguments[1].first );
} }
else if ( hour instanceof CArray ) { else if ( hour instanceof cArray ) {
hour = hour.getElement( 0 ); hour = hour.getElement( 0 );
} }
if ( minute instanceof CArea || minute instanceof CArea3D ) { if ( minute instanceof cArea || minute instanceof cArea3D ) {
minute = minute.cross( arguments[1].first ); minute = minute.cross( arguments[1].first );
} }
else if ( minute instanceof CArray ) { else if ( minute instanceof cArray ) {
minute = minute.getElement( 0 ); minute = minute.getElement( 0 );
} }
if ( second instanceof CArea || second instanceof CArea3D ) { if ( second instanceof cArea || second instanceof cArea3D ) {
second = second.cross( arguments[1].first ); second = second.cross( arguments[1].first );
} }
else if ( second instanceof CArray ) { else if ( second instanceof cArray ) {
second = second.getElement( 0 ); second = second.getElement( 0 );
} }
...@@ -1282,16 +1283,16 @@ cTIME.prototype.Calculate = function ( arg ) { ...@@ -1282,16 +1283,16 @@ cTIME.prototype.Calculate = function ( arg ) {
minute = minute.tocNumber(); minute = minute.tocNumber();
second = second.tocNumber(); second = second.tocNumber();
if ( hour instanceof CError ) return this.setCA( hour, true ); if ( hour instanceof cError ) return this.setCA( hour, true );
if ( minute instanceof CError ) return this.setCA( minute, true ); if ( minute instanceof cError ) return this.setCA( minute, true );
if ( second instanceof CError ) return this.setCA( second, true ); if ( second instanceof cError ) return this.setCA( second, true );
hour = hour.getValue(); hour = hour.getValue();
minute = minute.getValue(); minute = minute.getValue();
second = second.getValue(); second = second.getValue();
var v = (hour * 60 * 60 + minute * 60 + second) / c_sPerDay; var v = (hour * 60 * 60 + minute * 60 + second) / c_sPerDay;
this.setCA( new CNumber( v - Math.floor( v ) ), true ); this.setCA( new cNumber( v - Math.floor( v ) ), true );
if ( arguments[1].getNumFormatStr().toLowerCase() === "general" ) if ( arguments[1].getNumFormatStr().toLowerCase() === "general" )
this.value.numFormat = 18; this.value.numFormat = 18;
return this.value; return this.value;
...@@ -1326,27 +1327,27 @@ cTIMEVALUE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1326,27 +1327,27 @@ cTIMEVALUE.prototype = Object.create( cBaseFunction.prototype )
cTIMEVALUE.prototype.Calculate = function ( arg ) { cTIMEVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if ( arg0.tocNumber() instanceof CNumber && arg0.tocNumber().getValue() > 0 ) if ( arg0.tocNumber() instanceof cNumber && arg0.tocNumber().getValue() > 0 )
return this.value = new CNumber( parseInt( arg0.tocNumber().getValue() ) ); return this.value = new cNumber( parseInt( arg0.tocNumber().getValue() ) );
var res = g_oFormatParser.parse( arg0.getValue() ); var res = g_oFormatParser.parse( arg0.getValue() );
if ( res && res.bDateTime ) if ( res && res.bDateTime )
return this.value = new CNumber( res.value - parseInt( res.value ) ); return this.value = new cNumber( res.value - parseInt( res.value ) );
else else
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
cTIMEVALUE.prototype.getInfo = function () { cTIMEVALUE.prototype.getInfo = function () {
return { return {
...@@ -1375,7 +1376,7 @@ function cTODAY() { ...@@ -1375,7 +1376,7 @@ function cTODAY() {
} }
cTODAY.prototype = Object.create( cBaseFunction.prototype ) cTODAY.prototype = Object.create( cBaseFunction.prototype )
cTODAY.prototype.Calculate = function () { cTODAY.prototype.Calculate = function () {
this.setCA( new CNumber( new Date().getExcelDate() ), true ); this.setCA( new cNumber( new Date().getExcelDate() ), true );
if ( arguments[1].getNumFormatStr().toLowerCase() === "general" ) if ( arguments[1].getNumFormatStr().toLowerCase() === "general" )
this.value.numFormat = 14; this.value.numFormat = 14;
return this.value; return this.value;
...@@ -1408,29 +1409,29 @@ function cWEEKDAY() { ...@@ -1408,29 +1409,29 @@ function cWEEKDAY() {
} }
cWEEKDAY.prototype = Object.create( cBaseFunction.prototype ) cWEEKDAY.prototype = Object.create( cBaseFunction.prototype )
cWEEKDAY.prototype.Calculate = function ( arg ) { cWEEKDAY.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new CNumber( 1 ); var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new cNumber( 1 );
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof CError ) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
var weekday; var weekday;
...@@ -1463,12 +1464,12 @@ cWEEKDAY.prototype.Calculate = function ( arg ) { ...@@ -1463,12 +1464,12 @@ cWEEKDAY.prototype.Calculate = function ( arg ) {
weekday = [2, 3, 4, 5, 6, 7, 1]; weekday = [2, 3, 4, 5, 6, 7, 1];
break; break;
default: default:
return this.value = new CError( cErrorType.not_numeric ); return this.value = new cError( cErrorType.not_numeric );
} }
if ( arg0.getValue() < 0 ) if ( arg0.getValue() < 0 )
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new CNumber( weekday[new Date( (arg0.getValue() - (c_DateCorrectConst + 1)) * c_msPerDay ).getDay()] ); return this.value = new cNumber( weekday[new Date( (arg0.getValue() - (c_DateCorrectConst + 1)) * c_msPerDay ).getDay()] );
} }
cWEEKDAY.prototype.getInfo = function () { cWEEKDAY.prototype.getInfo = function () {
return { return {
...@@ -1498,7 +1499,7 @@ function cWEEKNUM() { ...@@ -1498,7 +1499,7 @@ function cWEEKNUM() {
} }
cWEEKNUM.prototype = Object.create( cBaseFunction.prototype ) cWEEKNUM.prototype = Object.create( cBaseFunction.prototype )
cWEEKNUM.prototype.Calculate = function ( arg ) { cWEEKNUM.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new CNumber( 1 ), type = 0; var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new cNumber( 1 ), type = 0;
function WeekNumber( dt, iso, type ) { function WeekNumber( dt, iso, type ) {
dt.setHours( 0, 0, 0 ); dt.setHours( 0, 0, 0 );
...@@ -1516,43 +1517,43 @@ cWEEKNUM.prototype.Calculate = function ( arg ) { ...@@ -1516,43 +1517,43 @@ cWEEKNUM.prototype.Calculate = function ( arg ) {
case 53: case 53:
// Если 31 декабря выпадает до четверга 1 недели следующего года // Если 31 декабря выпадает до четверга 1 недели следующего года
if ( endOfYear.getDay() < 4 ) if ( endOfYear.getDay() < 4 )
return new CNumber( 1 ); return new cNumber( 1 );
else else
return new CNumber( wk ); return new cNumber( wk );
default: default:
return new CNumber( wk ); return new cNumber( wk );
} }
else { else {
wk = parseInt( ((dt - startOfYear) / c_msPerDay + iso[startOfYear.getDay()] + 7) / 7 ); wk = parseInt( ((dt - startOfYear) / c_msPerDay + iso[startOfYear.getDay()] + 7) / 7 );
return new CNumber( wk ); return new cNumber( wk );
} }
} }
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof CError ) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
if ( arg0.getValue() < 0 ) if ( arg0.getValue() < 0 )
return this.value = new CError( cErrorType.not_numeric ); return this.value = new cError( cErrorType.not_numeric );
var weekdayStartDay; var weekdayStartDay;
...@@ -1586,10 +1587,10 @@ cWEEKNUM.prototype.Calculate = function ( arg ) { ...@@ -1586,10 +1587,10 @@ cWEEKNUM.prototype.Calculate = function ( arg ) {
type = 1; type = 1;
break; break;
default: default:
return this.value = new CError( cErrorType.not_numeric ); return this.value = new cError( cErrorType.not_numeric );
} }
return this.value = new CNumber( WeekNumber( new Date( (arg0.getValue() - (c_DateCorrectConst + 1)) * c_msPerDay ), weekdayStartDay, type ) ); return this.value = new cNumber( WeekNumber( new Date( (arg0.getValue() - (c_DateCorrectConst + 1)) * c_msPerDay ), weekdayStartDay, type ) );
} }
cWEEKNUM.prototype.getInfo = function () { cWEEKNUM.prototype.getInfo = function () {
...@@ -1622,30 +1623,30 @@ cWORKDAY.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1622,30 +1623,30 @@ cWORKDAY.prototype = Object.create( cBaseFunction.prototype )
cWORKDAY.prototype.Calculate = function ( arg ) { cWORKDAY.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = []; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = [];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
var val0 = arg0.getValue(), val1 = arg1.getValue(), holidays = [] var val0 = arg0.getValue(), val1 = arg1.getValue(), holidays = []
if ( val0 < 0 ) if ( val0 < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val0 < 60 ) if ( val0 < 60 )
val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay ); val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay );
...@@ -1658,23 +1659,23 @@ cWORKDAY.prototype.Calculate = function ( arg ) { ...@@ -1658,23 +1659,23 @@ cWORKDAY.prototype.Calculate = function ( arg ) {
val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay ); val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay );
if ( arg2 ) { if ( arg2 ) {
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
var arr = arg2.getValue(); var arr = arg2.getValue();
for ( var i = 0; i < arr.length; i++ ) { for ( var i = 0; i < arr.length; i++ ) {
if ( arr[i] instanceof CNumber && arr[i].getValue() >= 0 ) { if ( arr[i] instanceof cNumber && arr[i].getValue() >= 0 ) {
holidays.push( arr[i] ); holidays.push( arr[i] );
} }
} }
} }
else if ( arg2 instanceof CArray ) { else if ( arg2 instanceof cArray ) {
arg2.foreach( function ( elem, r, c ) { arg2.foreach( function ( elem, r, c ) {
if ( elem instanceof CNumber ) { if ( elem instanceof cNumber ) {
holidays.push( elem ); holidays.push( elem );
} }
else if ( elem instanceof CString ) { else if ( elem instanceof cString ) {
var res = g_oFormatParser.parse( elem.getValue() ); var res = g_oFormatParser.parse( elem.getValue() );
if ( res && res.bDateTime && res.value >= 0 ) if ( res && res.bDateTime && res.value >= 0 )
holidays.push( new CNumber( parseInt( res.value ) ) ); holidays.push( new cNumber( parseInt( res.value ) ) );
} }
} ) } )
} }
...@@ -1712,12 +1713,12 @@ cWORKDAY.prototype.Calculate = function ( arg ) { ...@@ -1712,12 +1713,12 @@ cWORKDAY.prototype.Calculate = function ( arg ) {
val = parseInt( ( date.getTime() / 1000 - date.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) ); val = parseInt( ( date.getTime() / 1000 - date.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
if ( val < 0 ) if ( val < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
if ( arguments[1].getNumFormatStr().toLowerCase() === "general" ) if ( arguments[1].getNumFormatStr().toLowerCase() === "general" )
return this.setCA( new CNumber( val ), true, 14 ); return this.setCA( new cNumber( val ), true, 14 );
else else
return this.setCA( new CNumber( val ), true ); return this.setCA( new cNumber( val ), true );
} }
cWORKDAY.prototype.getInfo = function () { cWORKDAY.prototype.getInfo = function () {
return { return {
...@@ -1753,36 +1754,36 @@ function cYEAR() { ...@@ -1753,36 +1754,36 @@ function cYEAR() {
cYEAR.prototype = Object.create( cBaseFunction.prototype ) cYEAR.prototype = Object.create( cBaseFunction.prototype )
cYEAR.prototype.Calculate = function ( arg ) { cYEAR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof CError ) return this.setCA( arg0, true ); if ( arg0 instanceof cError ) return this.setCA( arg0, true );
else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) { else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof CError ) return this.setCA( val, true ); if ( val instanceof cError ) return this.setCA( val, true );
else if ( val instanceof CNumber || val instanceof CBool ) { else if ( val instanceof cNumber || val instanceof cBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof CString ) { else if ( arg0 instanceof cString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof CError || val instanceof CEmpty ) { if ( val instanceof cError || val instanceof cEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
return this.setCA( new CError( cErrorType.wrong_value_type ), true ); return this.setCA( new cError( cErrorType.wrong_value_type ), true );
} }
else else
val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) ); val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
...@@ -1792,9 +1793,9 @@ cYEAR.prototype.Calculate = function ( arg ) { ...@@ -1792,9 +1793,9 @@ cYEAR.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true, 0 ); return this.setCA( new cError( cErrorType.not_numeric ), true, 0 );
else else
return this.setCA( new CNumber( (new Date( (val - (c_DateCorrectConst + 1)) * c_msPerDay )).getUTCFullYear() ), true, 0 ); return this.setCA( new cNumber( (new Date( (val - (c_DateCorrectConst + 1)) * c_msPerDay )).getUTCFullYear() ), true, 0 );
} }
cYEAR.prototype.getInfo = function () { cYEAR.prototype.getInfo = function () {
return { return {
...@@ -1824,25 +1825,25 @@ function cYEARFRAC() { ...@@ -1824,25 +1825,25 @@ function cYEARFRAC() {
} }
cYEARFRAC.prototype = Object.create( cBaseFunction.prototype ) cYEARFRAC.prototype = Object.create( cBaseFunction.prototype )
cYEARFRAC.prototype.Calculate = function ( arg ) { cYEARFRAC.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new CNumber( 0 ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber( 0 );
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
else if ( arg2 instanceof CArray ) { else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElementRowCol( 0, 0 ); arg2 = arg2.getElementRowCol( 0, 0 );
} }
...@@ -1850,14 +1851,14 @@ cYEARFRAC.prototype.Calculate = function ( arg ) { ...@@ -1850,14 +1851,14 @@ cYEARFRAC.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof CError ) return this.value = arg2; if ( arg2 instanceof cError ) return this.value = arg2;
var val0 = arg0.getValue(), val1 = arg1.getValue(); var val0 = arg0.getValue(), val1 = arg1.getValue();
if ( val0 < 0 || val1 < 0 ) if ( val0 < 0 || val1 < 0 )
return this.setCA( new CError( cErrorType.not_numeric ), true ); return this.setCA( new cError( cErrorType.not_numeric ), true );
val0 = Date.prototype.getDateFromExcel( val0 ); val0 = Date.prototype.getDateFromExcel( val0 );
val1 = Date.prototype.getDateFromExcel( val1 ); val1 = Date.prototype.getDateFromExcel( val1 );
......
...@@ -54,9 +54,9 @@ var f_2_DIV_PI = 2.0 / Math.PI; ...@@ -54,9 +54,9 @@ var f_2_DIV_PI = 2.0 / Math.PI;
function BesselJ( x, N ) { function BesselJ( x, N ) {
if ( N < 0 ){ if ( N < 0 ){
return new CError( cErrorType.not_numeric );} return new cError( cErrorType.not_numeric );}
if ( x === 0.0 ){ if ( x === 0.0 ){
return new CNumber( (N == 0) ? 1 : 0 );} return new cNumber( (N == 0) ? 1 : 0 );}
/* The algorithm works only for x>0, therefore remember sign. BesselJ /* The algorithm works only for x>0, therefore remember sign. BesselJ
with integer order N is an even function for even N (means J(-x)=J(x)) with integer order N is an even function for even N (means J(-x)=J(x))
...@@ -69,9 +69,9 @@ function BesselJ( x, N ) { ...@@ -69,9 +69,9 @@ function BesselJ( x, N ) {
var bAsymptoticPossible = Math.pow( fX, 0.4 ) > N; var bAsymptoticPossible = Math.pow( fX, 0.4 ) > N;
if ( fEstimateIteration > fMaxIteration ) { if ( fEstimateIteration > fMaxIteration ) {
if ( bAsymptoticPossible ){ if ( bAsymptoticPossible ){
return new CNumber(fSign * Math.sqrt( f_2_DIV_PI / fX ) * Math.cos( fX - N * f_PI_DIV_2 - f_PI_DIV_4 ) );} return new cNumber(fSign * Math.sqrt( f_2_DIV_PI / fX ) * Math.cos( fX - N * f_PI_DIV_2 - f_PI_DIV_4 ) );}
else{ else{
return new CError(cErrorType.not_numeric);} return new cError(cErrorType.not_numeric);}
} }
var epsilon = 1.0e-15; // relative error var epsilon = 1.0e-15; // relative error
...@@ -125,15 +125,15 @@ function BesselJ( x, N ) { ...@@ -125,15 +125,15 @@ function BesselJ( x, N ) {
} }
while ( !bHasfound && k <= fMaxIteration ); while ( !bHasfound && k <= fMaxIteration );
if ( bHasfound ){ if ( bHasfound ){
return new CNumber( u * fSign );} return new cNumber( u * fSign );}
else{ else{
return new CError(cErrorType.not_numeric);}// unlikely to happen return new cError(cErrorType.not_numeric);}// unlikely to happen
} }
function BesselI( x, n ) { function BesselI( x, n ) {
var nMaxIteration = 2000, fXHalf = x / 2, fResult = 0; var nMaxIteration = 2000, fXHalf = x / 2, fResult = 0;
if ( n < 0 ){ if ( n < 0 ){
return new CError( cErrorType.not_numeric );} return new cError( cErrorType.not_numeric );}
/* Start the iteration without TERM(n,0), which is set here. /* Start the iteration without TERM(n,0), which is set here.
...@@ -175,7 +175,7 @@ function BesselI( x, n ) { ...@@ -175,7 +175,7 @@ function BesselI( x, n ) {
while ( (Math.abs( fTerm ) > Math.abs( fResult ) * fEpsilon) && (nK < nMaxIteration) ); while ( (Math.abs( fTerm ) > Math.abs( fResult ) * fEpsilon) && (nK < nMaxIteration) );
} }
return new CNumber( fResult ); return new cNumber( fResult );
} }
function Besselk0( fNum ) { function Besselk0( fNum ) {
...@@ -239,7 +239,7 @@ function BesselK( fNum, nOrder ) { ...@@ -239,7 +239,7 @@ function BesselK( fNum, nOrder ) {
function Bessely0( fX ) { function Bessely0( fX ) {
if ( fX <= 0 ) if ( fX <= 0 )
return new CError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
var fMaxIteration = 9000000; // should not be reached var fMaxIteration = 9000000; // should not be reached
if ( fX > 5.0e+6 ) // iteration is not considerable better then approximation if ( fX > 5.0e+6 ) // iteration is not considerable better then approximation
return Math.sqrt( 1 / Math.PI / fX ) * (Math.sin( fX ) - Math.cos( fX )); return Math.sqrt( 1 / Math.PI / fX ) * (Math.sin( fX ) - Math.cos( fX ));
...@@ -274,14 +274,14 @@ function Bessely0( fX ) { ...@@ -274,14 +274,14 @@ function Bessely0( fX ) {
if ( bHasFound ) if ( bHasFound )
return u * f_2_DIV_PI; return u * f_2_DIV_PI;
else else
return new CError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
} }
// See #i31656# for a commented version of this implementation, attachment #desc6 // See #i31656# for a commented version of this implementation, attachment #desc6
// http://www.openoffice.org/nonav/issues/showattachment.cgi/63609/Comments%20to%20the%20implementation%20of%20the%20Bessel%20functions.odt // http://www.openoffice.org/nonav/issues/showattachment.cgi/63609/Comments%20to%20the%20implementation%20of%20the%20Bessel%20functions.odt
function Bessely1( fX ) { function Bessely1( fX ) {
if ( fX <= 0 ) if ( fX <= 0 )
return new CError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
var fMaxIteration = 9000000; // should not be reached var fMaxIteration = 9000000; // should not be reached
if ( fX > 5e+6 ) // iteration is not considerable better then approximation if ( fX > 5e+6 ) // iteration is not considerable better then approximation
return -Math.sqrt( 1 / Math.PI / fX ) * (Math.sin( fX ) + Math.cos( fX )); return -Math.sqrt( 1 / Math.PI / fX ) * (Math.sin( fX ) + Math.cos( fX ));
...@@ -320,7 +320,7 @@ function Bessely1( fX ) { ...@@ -320,7 +320,7 @@ function Bessely1( fX ) {
if ( bHasFound ) if ( bHasFound )
return -u * 2 / Math.PI; return -u * 2 / Math.PI;
else else
return new CError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
} }
function BesselY( fNum, nOrder ) { function BesselY( fNum, nOrder ) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -24,7 +24,7 @@ cFormulaFunction.Information = { ...@@ -24,7 +24,7 @@ cFormulaFunction.Information = {
'N':cN, 'N':cN,
'NA':cNA, 'NA':cNA,
'TYPE':cTYPE 'TYPE':cTYPE
} };
/* /*
здесь вынесены функции, которы по назначению не могут быть использованы в веб редакторах документах. здесь вынесены функции, которы по назначению не могут быть использованы в веб редакторах документах.
либо они будут реализованы с усеченным функционалом позже. либо они будут реализованы с усеченным функционалом позже.
...@@ -54,65 +54,60 @@ function cERROR_TYPE() { ...@@ -54,65 +54,60 @@ function cERROR_TYPE() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cERROR_TYPE.prototype = Object.create( cBaseFunction.prototype ) cERROR_TYPE.prototype = Object.create( cBaseFunction.prototype );
cERROR_TYPE.prototype.Calculate = function ( arg ) { cERROR_TYPE.prototype.Calculate = function ( arg ) {
function typeError( elem ) { function typeError( elem ) {
if ( elem instanceof CError ) { if ( elem instanceof cError ) {
if ( elem.errorType == cErrorType.null_value ) { switch ( elem.errorType ) {
return new CNumber( 1 ); case cErrorType.null_value:
} return new cNumber( 1 );
else if ( elem.errorType == cErrorType.division_by_zero ) { case cErrorType.division_by_zero:
return new CNumber( 2 ); return new cNumber( 2 );
} case cErrorType.wrong_value_type:
else if ( elem.errorType == cErrorType.wrong_value_type ) { return new cNumber( 3 );
return new CNumber( 3 ); case cErrorType.bad_reference :
} return new cNumber( 4 );
else if ( elem.errorType == cErrorType.bad_reference ) { case cErrorType.wrong_name :
return new CNumber( 4 ); return new cNumber( 5 );
} case cErrorType.not_numeric :
else if ( elem.errorType == cErrorType.wrong_name ) { return new cNumber( 6 );
return new CNumber( 5 ); case cErrorType.not_available :
} return new cNumber( 7 );
else if ( elem.errorType == cErrorType.not_numeric ) { case cErrorType.getting_data :
return new CNumber( 6 ); return new cNumber( 8 );
} default:
else if ( elem.errorType == cErrorType.not_available ) { return new cError( cErrorType.not_available );
return new CNumber( 7 );
}
else if ( elem.errorType == cErrorType.getting_data ) {
return new CNumber( 8 );
}
else {
return new CError( cErrorType.not_available );
} }
} }
else return new CError( cErrorType.not_available ); else {
return new cError( cErrorType.not_available );
}
} }
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
var ret = new CArray(); var ret = new cArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
if ( !ret.array[r] ) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
ret.addElement( found_operand ) ret.addElement( found_operand );
} ) } );
return this.value = ret; return this.value = ret;
} }
return this.value = typeError( arg0 ); return this.value = typeError( arg0 );
} };
cERROR_TYPE.prototype.getInfo = function () { cERROR_TYPE.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cISBLANK() { function cISBLANK() {
// cBaseFunction.call( this, "ISBLANK" ); // cBaseFunction.call( this, "ISBLANK" );
...@@ -132,26 +127,26 @@ function cISBLANK() { ...@@ -132,26 +127,26 @@ function cISBLANK() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISBLANK.prototype = Object.create( cBaseFunction.prototype ) cISBLANK.prototype = Object.create( cBaseFunction.prototype );
cISBLANK.prototype.Calculate = function ( arg ) { cISBLANK.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CEmpty ) if ( arg0 instanceof cEmpty )
return this.value = new CBool( true ); return this.value = new cBool( true );
else else
return this.value = new CBool( false ); return this.value = new cBool( false );
} };
cISBLANK.prototype.getInfo = function () { cISBLANK.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cISERR() { function cISERR() {
// cBaseFunction.call( this, "ISERR" ); // cBaseFunction.call( this, "ISERR" );
...@@ -171,30 +166,30 @@ function cISERR() { ...@@ -171,30 +166,30 @@ function cISERR() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISERR.prototype = Object.create( cBaseFunction.prototype ) cISERR.prototype = Object.create( cBaseFunction.prototype );
cISERR.prototype.Calculate = function ( arg ) { cISERR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CError && arg0.errorType != cErrorType.not_available ) if ( arg0 instanceof cError && arg0.errorType != cErrorType.not_available )
return this.value = new CBool( true ); return this.value = new cBool( true );
else else
return this.value = new CBool( false ); return this.value = new cBool( false );
} };
cISERR.prototype.getInfo = function () { cISERR.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cISERROR() { function cISERROR() {
// cBaseFunction.call( this, "ISERROR" ); // cBaseFunction.call( this, "ISERROR" );
...@@ -214,30 +209,30 @@ function cISERROR() { ...@@ -214,30 +209,30 @@ function cISERROR() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISERROR.prototype = Object.create( cBaseFunction.prototype ) cISERROR.prototype = Object.create( cBaseFunction.prototype );
cISERROR.prototype.Calculate = function ( arg ) { cISERROR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = new CBool( true ); return this.value = new cBool( true );
else else
return this.value = new CBool( false ); return this.value = new cBool( false );
} };
cISERROR.prototype.getInfo = function () { cISERROR.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cISEVEN() { function cISEVEN() {
// cBaseFunction.call( this, "ISEVEN" ); // cBaseFunction.call( this, "ISEVEN" );
...@@ -257,34 +252,34 @@ function cISEVEN() { ...@@ -257,34 +252,34 @@ function cISEVEN() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISEVEN.prototype = Object.create( cBaseFunction.prototype ) cISEVEN.prototype = Object.create( cBaseFunction.prototype );
cISEVEN.prototype.Calculate = function ( arg ) { cISEVEN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
var arg0 = arg0.tocNumber(); var arg0 = arg0.tocNumber();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
else else
return this.value = new CBool( (arg0.getValue() & 1) == 0 ); return this.value = new cBool( (arg0.getValue() & 1) == 0 );
} };
cISEVEN.prototype.getInfo = function () { cISEVEN.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(number)" args:"(number)"
}; };
} };
function cISLOGICAL() { function cISLOGICAL() {
// cBaseFunction.call( this, "ISLOGICAL" ); // cBaseFunction.call( this, "ISLOGICAL" );
...@@ -304,29 +299,29 @@ function cISLOGICAL() { ...@@ -304,29 +299,29 @@ function cISLOGICAL() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISLOGICAL.prototype = Object.create( cBaseFunction.prototype ) cISLOGICAL.prototype = Object.create( cBaseFunction.prototype );
cISLOGICAL.prototype.Calculate = function ( arg ) { cISLOGICAL.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CBool ) if ( arg0 instanceof cBool )
return this.value = new CBool( true ); return this.value = new cBool( true );
else return this.value = new CBool( false ); else return this.value = new cBool( false );
} };
cISLOGICAL.prototype.getInfo = function () { cISLOGICAL.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cISNA() { function cISNA() {
// cBaseFunction.call( this, "ISNA" ); // cBaseFunction.call( this, "ISNA" );
...@@ -346,30 +341,30 @@ function cISNA() { ...@@ -346,30 +341,30 @@ function cISNA() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISNA.prototype = Object.create( cBaseFunction.prototype ) cISNA.prototype = Object.create( cBaseFunction.prototype );
cISNA.prototype.Calculate = function ( arg ) { cISNA.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CError && arg0.errorType == cErrorType.not_available ) if ( arg0 instanceof cError && arg0.errorType == cErrorType.not_available )
return this.value = new CBool( true ); return this.value = new cBool( true );
else else
return this.value = new CBool( false ); return this.value = new cBool( false );
} };
cISNA.prototype.getInfo = function () { cISNA.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cISNONTEXT() { function cISNONTEXT() {
// cBaseFunction.call( this, "ISNONTEXT" ); // cBaseFunction.call( this, "ISNONTEXT" );
...@@ -389,29 +384,29 @@ function cISNONTEXT() { ...@@ -389,29 +384,29 @@ function cISNONTEXT() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISNONTEXT.prototype = Object.create( cBaseFunction.prototype ) cISNONTEXT.prototype = Object.create( cBaseFunction.prototype );
cISNONTEXT.prototype.Calculate = function ( arg ) { cISNONTEXT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( !(arg0 instanceof CString) ) if ( !(arg0 instanceof cString) )
return this.value = new CBool( true ); return this.value = new cBool( true );
else else
return this.value = new CBool( false ); return this.value = new cBool( false );
} };
cISNONTEXT.prototype.getInfo = function () { cISNONTEXT.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cISNUMBER() { function cISNUMBER() {
// cBaseFunction.call( this, "ISNUMBER" ); // cBaseFunction.call( this, "ISNUMBER" );
...@@ -431,30 +426,30 @@ function cISNUMBER() { ...@@ -431,30 +426,30 @@ function cISNUMBER() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISNUMBER.prototype = Object.create( cBaseFunction.prototype ) cISNUMBER.prototype = Object.create( cBaseFunction.prototype );
cISNUMBER.prototype.Calculate = function ( arg ) { cISNUMBER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CNumber ) if ( arg0 instanceof cNumber )
return this.value = new CBool( true ); return this.value = new cBool( true );
else else
return this.value = new CBool( false ); return this.value = new cBool( false );
} };
cISNUMBER.prototype.getInfo = function () { cISNUMBER.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cISODD() { function cISODD() {
// cBaseFunction.call( this, "ISODD" ); // cBaseFunction.call( this, "ISODD" );
...@@ -474,34 +469,34 @@ function cISODD() { ...@@ -474,34 +469,34 @@ function cISODD() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISODD.prototype = Object.create( cBaseFunction.prototype ) cISODD.prototype = Object.create( cBaseFunction.prototype );
cISODD.prototype.Calculate = function ( arg ) { cISODD.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
var arg0 = arg0.tocNumber(); var arg0 = arg0.tocNumber();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
else else
return this.value = new CBool( (arg0.getValue() & 1) == 1 ); return this.value = new cBool( (arg0.getValue() & 1) == 1 );
} };
cISODD.prototype.getInfo = function () { cISODD.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(number)" args:"(number)"
}; };
} };
function cISREF() { function cISREF() {
// cBaseFunction.call( this, "ISREF" ); // cBaseFunction.call( this, "ISREF" );
...@@ -521,18 +516,18 @@ function cISREF() { ...@@ -521,18 +516,18 @@ function cISREF() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISREF.prototype = Object.create( cBaseFunction.prototype ) cISREF.prototype = Object.create( cBaseFunction.prototype );
cISREF.prototype.Calculate = function ( arg ) { cISREF.prototype.Calculate = function ( arg ) {
if ( (arg[0] instanceof CRef || arg[0] instanceof CArea || arg[0] instanceof CArea3D || arg[0] instanceof CRef3D) && arg[0].isValid && arg[0].isValid() ) if ( (arg[0] instanceof cRef || arg[0] instanceof cArea || arg[0] instanceof cArea3D || arg[0] instanceof cRef3D) && arg[0].isValid && arg[0].isValid() )
return this.value = new CBool( true ); return this.value = new cBool( true );
else return this.value = new CBool( false ); else return this.value = new cBool( false );
} };
cISREF.prototype.getInfo = function () { cISREF.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cISTEXT() { function cISTEXT() {
// cBaseFunction.call( this, "ISTEXT" ); // cBaseFunction.call( this, "ISTEXT" );
...@@ -552,30 +547,30 @@ function cISTEXT() { ...@@ -552,30 +547,30 @@ function cISTEXT() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cISTEXT.prototype = Object.create( cBaseFunction.prototype ) cISTEXT.prototype = Object.create( cBaseFunction.prototype );
cISTEXT.prototype.Calculate = function ( arg ) { cISTEXT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CString ) if ( arg0 instanceof cString )
return this.value = new CBool( true ); return this.value = new cBool( true );
else else
return this.value = new CBool( false ); return this.value = new cBool( false );
} };
cISTEXT.prototype.getInfo = function () { cISTEXT.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cN() { function cN() {
// cBaseFunction.call( this, "N" ); // cBaseFunction.call( this, "N" );
...@@ -596,42 +591,42 @@ function cN() { ...@@ -596,42 +591,42 @@ function cN() {
this.numFormat = this.formatType.noneFormat; this.numFormat = this.formatType.noneFormat;
} }
cN.prototype = Object.create( cBaseFunction.prototype ) cN.prototype = Object.create( cBaseFunction.prototype );
cN.prototype.Calculate = function ( arg ) { cN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
var arr = new CArray(); var arr = new cArray();
arg.foreach( function ( elem, r, c ) { arg.foreach( function ( elem, r, c ) {
if ( elem instanceof CNumber || elem instanceof CError ) if ( elem instanceof cNumber || elem instanceof cError )
arr.array[r][c] = elem; arr.array[r][c] = elem;
else if ( elem instanceof CBool ) else if ( elem instanceof cBool )
arr.array[r][c] = elem.tocNumber(); arr.array[r][c] = elem.tocNumber();
else else
arr.array[r][c] = new CNumber( 0 ); arr.array[r][c] = new cNumber( 0 );
} ) } )
return this.value = arr; return this.value = arr;
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CNumber || arg0 instanceof CError ) if ( arg0 instanceof cNumber || arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
else if ( arg0 instanceof CBool ) else if ( arg0 instanceof cBool )
return this.value = arg0.tocNumber(); return this.value = arg0.tocNumber();
else else
return this.value = new CNumber( 0 ); return this.value = new cNumber( 0 );
} };
cN.prototype.getInfo = function () { cN.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
function cNA() { function cNA() {
// cBaseFunction.call( this, "NA" ); // cBaseFunction.call( this, "NA" );
...@@ -651,16 +646,16 @@ function cNA() { ...@@ -651,16 +646,16 @@ function cNA() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cNA.prototype = Object.create( cBaseFunction.prototype ) cNA.prototype = Object.create( cBaseFunction.prototype );
cNA.prototype.Calculate = function () { cNA.prototype.Calculate = function () {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} };
cNA.prototype.getInfo = function () { cNA.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"()" args:"()"
}; };
} };
function cTYPE() { function cTYPE() {
// cBaseFunction.call( this, "TYPE" ); // cBaseFunction.call( this, "TYPE" );
...@@ -680,30 +675,30 @@ function cTYPE() { ...@@ -680,30 +675,30 @@ function cTYPE() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cTYPE.prototype = Object.create( cBaseFunction.prototype ) cTYPE.prototype = Object.create( cBaseFunction.prototype );
cTYPE.prototype.Calculate = function ( arg ) { cTYPE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CNumber ) if ( arg0 instanceof cNumber )
return this.value = new CNumber( 1 ); return this.value = new cNumber( 1 );
else if ( arg0 instanceof CString ) else if ( arg0 instanceof cString )
return this.value = new CNumber( 2 ) return this.value = new cNumber( 2 )
else if ( arg0 instanceof CBool ) else if ( arg0 instanceof cBool )
return this.value = new CNumber( 4 ) return this.value = new cNumber( 4 )
else if ( arg0 instanceof CError ) else if ( arg0 instanceof cError )
return this.value = new CNumber( 16 ) return this.value = new cNumber( 16 )
else else
return this.value = new CNumber( 64 ); return this.value = new cNumber( 64 );
} };
cTYPE.prototype.getInfo = function () { cTYPE.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value)" args:"(value)"
}; };
} };
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
* Time: 15:22 * Time: 15:22
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
"use strict";
cFormulaFunction.Logical = { cFormulaFunction.Logical = {
'groupName':"Logical", 'groupName':"Logical",
'AND':cAND, 'AND':cAND,
...@@ -17,7 +16,7 @@ cFormulaFunction.Logical = { ...@@ -17,7 +16,7 @@ cFormulaFunction.Logical = {
'NOT':cNOT, 'NOT':cNOT,
'OR':cOR, 'OR':cOR,
'TRUE':cTRUE 'TRUE':cTRUE
} };
function cAND() { function cAND() {
// cBaseFunction.call( this, "AND" ); // cBaseFunction.call( this, "AND" );
...@@ -37,69 +36,82 @@ function cAND() { ...@@ -37,69 +36,82 @@ function cAND() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cAND.prototype = Object.create( cBaseFunction.prototype ) cAND.prototype = Object.create( cBaseFunction.prototype );
cAND.prototype.Calculate = function ( arg ) { cAND.prototype.Calculate = function ( arg ) {
var argResult = null; var argResult = null;
for ( var i = 0; i < arg.length; i++ ) { for ( var i = 0; i < arg.length; i++ ) {
if ( arg[i] instanceof CArea || arg[i] instanceof CArea3D ) { if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ) {
var argArr = arg[i].getValue(); var argArr = arg[i].getValue();
for ( var j = 0; j < argArr.length; j++ ) { for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof CString || argArr[j] instanceof CEmpty ) continue; if ( argArr[j] instanceof cError ) {
else if ( argArr[j] instanceof CError ) return this.value = argArr[j]; return this.value = argArr[j];
else { }
if ( argResult == null ) else if ( !(argArr[j] instanceof cString || argArr[j] instanceof cEmpty) ) {
if ( argResult === null ) {
argResult = argArr[j].tocBool(); argResult = argArr[j].tocBool();
else }
argResult = new CBool( argResult.value && argArr[j].tocBool().value ); else {
if ( argResult.value == false ) return this.value = new CBool( false ); argResult = new cBool( argResult.value && argArr[j].tocBool().value );
}
if ( argResult.value === false ) {
return this.value = new cBool( false );
}
} }
} }
} }
else { else {
if ( arg[i] instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type ); if ( arg[i] instanceof cString ) {
else if ( arg[i] instanceof CError ) { return this.value = new cError( cErrorType.wrong_value_type );
}
else if ( arg[i] instanceof cError ) {
return this.value = arg[i]; return this.value = arg[i];
} }
else if ( arg[i] instanceof CArray ) { else if ( arg[i] instanceof cArray ) {
var thas = this;
arg[i].foreach( function ( elem ) { arg[i].foreach( function ( elem ) {
if ( elem instanceof CError ) { if ( elem instanceof cError ) {
argResult = elem; argResult = elem;
return true; return true;
} }
else if ( elem instanceof CString || elem instanceof CEmpty ) { else if ( elem instanceof cString || elem instanceof cEmpty ) {
return; return false;
} }
else { else {
if ( argResult == null ) if ( argResult === null ) {
argResult = elem.tocBool(); argResult = elem.tocBool();
else }
argResult = new CBool( argResult.value && elem.tocBool().value ); else {
if ( argResult.value == false ) { argResult = new cBool( argResult.value && elem.tocBool().value );
}
if ( argResult.value === false ) {
return true; return true;
} }
} }
} ) } );
} }
else { else {
if ( argResult == null ) if ( argResult === null ) {
argResult = arg[i].tocBool(); argResult = arg[i].tocBool();
else }
argResult = new CBool( argResult.value && arg[i].tocBool().value ); else {
if ( argResult.value == false ) return this.value = new CBool( false ); argResult = new cBool( argResult.value && arg[i].tocBool().value );
}
if ( argResult.value === false ) {
return this.value = new cBool( false );
}
} }
} }
} }
if ( argResult == null ) if ( argResult === null ) {
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
}
return this.value = argResult; return this.value = argResult;
} };
cAND.prototype.getInfo = function () { cAND.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(logical1, logical2, ...)" args:"(logical1, logical2, ...)"
}; };
} };
function cFALSE() { function cFALSE() {
// cBaseFunction.call( this, "FALSE" ); // cBaseFunction.call( this, "FALSE" );
...@@ -118,16 +130,16 @@ function cFALSE() { ...@@ -118,16 +130,16 @@ function cFALSE() {
}; };
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cFALSE.prototype = Object.create( cBaseFunction.prototype ) cFALSE.prototype = Object.create( cBaseFunction.prototype );
cFALSE.prototype.Calculate = function () { cFALSE.prototype.Calculate = function () {
return this.value = new CBool( false ); return this.value = new cBool( false );
} };
cFALSE.prototype.getInfo = function () { cFALSE.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"()" args:"()"
}; };
} };
function cIF() { function cIF() {
// cBaseFunction.call( this, "IF" ); // cBaseFunction.call( this, "IF" );
...@@ -147,43 +159,50 @@ function cIF() { ...@@ -147,43 +159,50 @@ function cIF() {
// this.setArgumentsMin( 1 ); // this.setArgumentsMin( 1 );
// this.setArgumentsMax( 3 ); // this.setArgumentsMax( 3 );
} }
cIF.prototype = Object.create( cBaseFunction.prototype ) cIF.prototype = Object.create( cBaseFunction.prototype );
cIF.prototype.Calculate = function ( arg ) { cIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if ( arg0 instanceof CArray ) if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
if ( arg1 instanceof CArray ) }
if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 ); arg1 = arg1.getElement( 0 );
if ( arg2 instanceof CArray ) }
if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement( 0 ); arg2 = arg2.getElement( 0 );
}
if ( arg0 instanceof CError ) if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
}
else { else {
arg0 = arg0.tocBool(); arg0 = arg0.tocBool();
if ( arg0 instanceof CString ) if ( arg0 instanceof cString ) {
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
else if ( arg0.value ) }
else if ( arg0.value ) {
return this.value = arg1 ? return this.value = arg1 ?
arg1 instanceof CEmpty ? arg1 instanceof cEmpty ?
new CNumber( 0 ) : new cNumber( 0 ) :
arg1 : arg1 :
new CBool( true ); new cBool( true );
}
else return this.value = arg2 ? else {
arg2 instanceof CEmpty ? return this.value = arg2 ?
new CNumber( 0 ) : arg2 instanceof cEmpty ?
new cNumber( 0 ) :
arg2 : arg2 :
new CBool( false ); new cBool( false );
}
} }
} };
cIF.prototype.getInfo = function () { cIF.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(logical_test, value_if_true, value_if_false)" args:"(logical_test, value_if_true, value_if_false)"
}; };
} };
function cIFERROR() { function cIFERROR() {
// cBaseFunction.call( this, "IFERROR" ); // cBaseFunction.call( this, "IFERROR" );
...@@ -203,29 +222,32 @@ function cIFERROR() { ...@@ -203,29 +222,32 @@ function cIFERROR() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cIFERROR.prototype = Object.create( cBaseFunction.prototype ) cIFERROR.prototype = Object.create( cBaseFunction.prototype );
cIFERROR.prototype.Calculate = function ( arg ) { cIFERROR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg0 instanceof CError ) if ( arg0 instanceof cError ) {
return this.value = arg[1] instanceof CArray ? arg[1].getElement( 0 ) : arg[1]; return this.value = arg[1] instanceof cArray ? arg[1].getElement( 0 ) : arg[1];
else return this.value = arg[0]; }
} else {
return this.value = arg[0];
}
};
cIFERROR.prototype.getInfo = function () { cIFERROR.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(value, value_if_error)" args:"(value, value_if_error)"
}; };
} };
function cNOT() { function cNOT() {
// cBaseFunction.call( this, "NOT" ); // cBaseFunction.call( this, "NOT" );
...@@ -245,34 +267,39 @@ function cNOT() { ...@@ -245,34 +267,39 @@ function cNOT() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cNOT.prototype = Object.create( cBaseFunction.prototype ) cNOT.prototype = Object.create( cBaseFunction.prototype );
cNOT.prototype.Calculate = function ( arg ) { cNOT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
}
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg0 instanceof CString ) { if ( arg0 instanceof cString ) {
var res = arg0.tocBool(); var res = arg0.tocBool();
if ( res instanceof CString ) if ( res instanceof cString ) {
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
else }
return this.value = new CBool( !res.value ); else {
return this.value = new cBool( !res.value );
}
} }
else if ( arg0 instanceof CError ) else if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
else }
return this.value = new CBool( !arg0.tocBool().value ); else {
} return this.value = new cBool( !arg0.tocBool().value );
}
};
cNOT.prototype.getInfo = function () { cNOT.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(logical)" args:"(logical)"
}; };
} };
function cOR() { function cOR() {
// cBaseFunction.call( this, "OR" ); // cBaseFunction.call( this, "OR" );
...@@ -292,64 +319,75 @@ function cOR() { ...@@ -292,64 +319,75 @@ function cOR() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cOR.prototype = Object.create( cBaseFunction.prototype ) cOR.prototype = Object.create( cBaseFunction.prototype );
cOR.prototype.Calculate = function ( arg ) { cOR.prototype.Calculate = function ( arg ) {
var argResult = null; var argResult = null;
for ( var i = 0; i < arg.length; i++ ) { for ( var i = 0; i < arg.length; i++ ) {
if ( arg[i] instanceof CArea || arg[i] instanceof CArea3D ) { if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ) {
var argArr = arg[i].getValue(); var argArr = arg[i].getValue();
for ( var j = 0; j < argArr.length; j++ ) { for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof CString || argArr[j] instanceof CEmpty ) continue; if ( argArr[j] instanceof cError ) {
else if ( argArr[j] instanceof CError ) return this.value = argArr[j]; return this.value = argArr[j];
else { }
if ( argResult == null ) else if ( argArr[j] instanceof cString || argArr[j] instanceof cEmpty ) {
if ( argResult === null ) {
argResult = argArr[j].tocBool(); argResult = argArr[j].tocBool();
else }
argResult = new CBool( argResult.value || argArr[j].tocBool().value ); else {
if ( argResult.value === true ) return this.value = new CBool( true ); argResult = new cBool( argResult.value || argArr[j].tocBool().value );
}
if ( argResult.value === true ) {
return this.value = new cBool( true );
}
} }
} }
} }
else { else {
if ( arg[i] instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type ); if ( arg[i] instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else if ( arg[i] instanceof CError ) return this.value = arg[i]; else if ( arg[i] instanceof cError ) return this.value = arg[i];
else if ( arg[i] instanceof CArray ) { else if ( arg[i] instanceof cArray ) {
var thas = this;
arg[i].foreach( function ( elem ) { arg[i].foreach( function ( elem ) {
if ( elem instanceof CError ) { if ( elem instanceof cError ) {
argResult = elem; argResult = elem;
return true; return true;
} }
else if ( elem instanceof CString || elem instanceof CEmpty ) { else if ( elem instanceof cString || elem instanceof cEmpty ) {
return; return false;
} }
else { else {
if ( argResult == null ) if ( argResult === null ) {
argResult = elem.tocBool(); argResult = elem.tocBool();
else }
argResult = new CBool( argResult.value || elem.tocBool().value ); else {
argResult = new cBool( argResult.value || elem.tocBool().value );
}
} }
} ) } )
} }
else { else {
if ( argResult == null ) if ( argResult == null ) {
argResult = arg[i].tocBool(); argResult = arg[i].tocBool();
else }
argResult = new CBool( argResult.value || arg[i].tocBool().value ); else {
if ( argResult.value === true ) return this.value = new CBool( true ); argResult = new cBool( argResult.value || arg[i].tocBool().value );
}
if ( argResult.value === true ) {
return this.value = new cBool( true );
}
} }
} }
} }
if ( argResult == null ) if ( argResult == null ) {
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
}
return this.value = argResult; return this.value = argResult;
} };
cOR.prototype.getInfo = function () { cOR.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(logical1, logical2, ...)" args:"(logical1, logical2, ...)"
}; };
} };
function cTRUE() { function cTRUE() {
// cBaseFunction.call( this, "TRUE" ); // cBaseFunction.call( this, "TRUE" );
...@@ -369,13 +407,13 @@ function cTRUE() { ...@@ -369,13 +407,13 @@ function cTRUE() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cTRUE.prototype = Object.create( cBaseFunction.prototype ) cTRUE.prototype = Object.create( cBaseFunction.prototype );
cTRUE.prototype.Calculate = function () { cTRUE.prototype.Calculate = function () {
return this.value = new CBool( true ); return this.value = new cBool( true );
} };
cTRUE.prototype.getInfo = function () { cTRUE.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"()" args:"()"
}; };
} };
...@@ -55,42 +55,42 @@ cADDRESS.prototype.Calculate = function ( arg ) { ...@@ -55,42 +55,42 @@ cADDRESS.prototype.Calculate = function ( arg ) {
} }
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 ),
sheetName = arg[4] ? arg[4] : new CEmpty(); sheetName = arg[4] ? arg[4] : new cEmpty();
if ( rowNumber instanceof CArea || rowNumber instanceof CArea3D ) { if ( rowNumber instanceof cArea || rowNumber instanceof cArea3D ) {
rowNumber = rowNumber.cross( arguments[1].first ); rowNumber = rowNumber.cross( arguments[1].first );
} }
else if ( rowNumber instanceof CArray ) { else if ( rowNumber instanceof cArray ) {
rowNumber = rowNumber.getElementRowCol( 0, 0 ); rowNumber = rowNumber.getElementRowCol( 0, 0 );
} }
if ( colNumber instanceof CArea || colNumber instanceof CArea3D ) { if ( colNumber instanceof cArea || colNumber instanceof cArea3D ) {
colNumber = colNumber.cross( arguments[1].first ); colNumber = colNumber.cross( arguments[1].first );
} }
else if ( colNumber instanceof CArray ) { else if ( colNumber instanceof cArray ) {
colNumber = colNumber.getElementRowCol( 0, 0 ); colNumber = colNumber.getElementRowCol( 0, 0 );
} }
if ( refType instanceof CArea || refType instanceof CArea3D ) { if ( refType instanceof cArea || refType instanceof cArea3D ) {
refType = refType.cross( arguments[1].first ); refType = refType.cross( arguments[1].first );
} }
else if ( refType instanceof CArray ) { else if ( refType instanceof cArray ) {
refType = refType.getElementRowCol( 0, 0 ); refType = refType.getElementRowCol( 0, 0 );
} }
if ( A1RefType instanceof CArea || A1RefType instanceof CArea3D ) { if ( A1RefType instanceof cArea || A1RefType instanceof cArea3D ) {
A1RefType = A1RefType.cross( arguments[1].first ); A1RefType = A1RefType.cross( arguments[1].first );
} }
else if ( A1RefType instanceof CArray ) { else if ( A1RefType instanceof cArray ) {
A1RefType = A1RefType.getElementRowCol( 0, 0 ); A1RefType = A1RefType.getElementRowCol( 0, 0 );
} }
if ( sheetName instanceof CArea || sheetName instanceof CArea3D ) { if ( sheetName instanceof cArea || sheetName instanceof cArea3D ) {
sheetName = sheetName.cross( arguments[1].first ); sheetName = sheetName.cross( arguments[1].first );
} }
else if ( sheetName instanceof CArray ) { else if ( sheetName instanceof cArray ) {
sheetName = sheetName.getElementRowCol( 0, 0 ); sheetName = sheetName.getElementRowCol( 0, 0 );
} }
...@@ -99,14 +99,14 @@ cADDRESS.prototype.Calculate = function ( arg ) { ...@@ -99,14 +99,14 @@ cADDRESS.prototype.Calculate = function ( arg ) {
refType = refType.tocNumber(); refType = refType.tocNumber();
A1RefType = A1RefType.tocBool(); A1RefType = A1RefType.tocBool();
if ( rowNumber instanceof CError ) return this.value = rowNumber; if ( rowNumber instanceof cError ) return this.value = rowNumber;
if ( colNumber instanceof CError ) return this.value = colNumber; if ( colNumber instanceof cError ) return this.value = colNumber;
if ( refType instanceof CError ) return this.value = refType; if ( refType instanceof cError ) return this.value = refType;
if ( A1RefType instanceof CError ) return this.value = A1RefType; if ( A1RefType instanceof cError ) return this.value = A1RefType;
if ( sheetName instanceof CError ) return this.value = sheetName; if ( sheetName instanceof cError ) return this.value = sheetName;
if ( refType.getValue() > 4 && refType.getValue() < 1 || rowNumber.getValue() < 1 || colNumber.getValue() < 1 ) { if ( refType.getValue() > 4 && refType.getValue() < 1 || rowNumber.getValue() < 1 || colNumber.getValue() < 1 ) {
return this.value = new CError( cErrorType.not_numeric ); return this.value = new cError( cErrorType.not_numeric );
} }
var strRef; var strRef;
switch ( refType.getValue() ) { switch ( refType.getValue() ) {
...@@ -124,15 +124,15 @@ cADDRESS.prototype.Calculate = function ( arg ) { ...@@ -124,15 +124,15 @@ cADDRESS.prototype.Calculate = function ( arg ) {
break; break;
} }
if ( sheetName instanceof CEmpty ) { if ( sheetName instanceof cEmpty ) {
return this.value = new CString( strRef ); return this.value = new cString( strRef );
} }
else { else {
if ( !rx_test_ws_name.test( sheetName.toString() ) ) { if ( !rx_test_ws_name.test( sheetName.toString() ) ) {
return this.value = new CString( "'" + sheetName.toString().replace( /'/g, "''" ) + "'" + "!" + strRef ); return this.value = new cString( "'" + sheetName.toString().replace( /'/g, "''" ) + "'" + "!" + strRef );
} }
else { else {
return this.value = new CString( sheetName.toString() + "!" + strRef ); return this.value = new cString( sheetName.toString() + "!" + strRef );
} }
} }
...@@ -171,24 +171,24 @@ cCHOOSE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -171,24 +171,24 @@ cCHOOSE.prototype = Object.create( cBaseFunction.prototype )
cCHOOSE.prototype.Calculate = function ( arg ) { cCHOOSE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
if ( arg0 instanceof CError ) { if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
if ( arg0 instanceof CNumber ) { if ( arg0 instanceof cNumber ) {
if ( arg0.getValue() < 1 || arg0.getValue() > this.getArguments() ) { if ( arg0.getValue() < 1 || arg0.getValue() > this.getArguments() ) {
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
return this.value = arg[arg0.getValue()]; return this.value = arg[arg0.getValue()];
} }
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
cCHOOSE.prototype.getInfo = function () { cCHOOSE.prototype.getInfo = function () {
return { return {
...@@ -220,27 +220,27 @@ cCOLUMN.prototype.Calculate = function ( arg ) { ...@@ -220,27 +220,27 @@ cCOLUMN.prototype.Calculate = function ( arg ) {
var arg0; var arg0;
if ( this.argumentsCurrent == 0 ) { if ( this.argumentsCurrent == 0 ) {
arg0 = arguments[1]; arg0 = arguments[1];
return this.value = new CNumber( arg0.getFirst().getCol() ); return this.value = new cNumber( arg0.getFirst().getCol() );
} }
arg0 = arg[0]; arg0 = arg[0];
if ( arg0 instanceof CRef || arg0 instanceof CRef3D || arg0 instanceof CArea ) { if ( arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea ) {
var range = arg0.getRange(); var range = arg0.getRange();
if ( range ) if ( range )
return this.value = new CNumber( range.getFirst().getCol() ); return this.value = new cNumber( range.getFirst().getCol() );
else else
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
else if ( arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea3D ) {
var r = arg0.getRange(); var r = arg0.getRange();
if ( r && r[0] && r[0].getFirst() ) { if ( r && r[0] && r[0].getFirst() ) {
return this.value = new CNumber( r[0].getFirst().getCol() ); return this.value = new cNumber( r[0].getFirst().getCol() );
} }
else { else {
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
} }
else else
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
cCOLUMN.prototype.getInfo = function () { cCOLUMN.prototype.getInfo = function () {
return { return {
...@@ -270,22 +270,22 @@ function cCOLUMNS() { ...@@ -270,22 +270,22 @@ function cCOLUMNS() {
cCOLUMNS.prototype = Object.create( cBaseFunction.prototype ) cCOLUMNS.prototype = Object.create( cBaseFunction.prototype )
cCOLUMNS.prototype.Calculate = function ( arg ) { cCOLUMNS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
return this.value = new CNumber( arg0.getCountElementInRow() ); return this.value = new cNumber( arg0.getCountElementInRow() );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cRef || arg0 instanceof cRef3D ) {
var range = arg0.getRange(); var range = arg0.getRange();
return this.value = new CNumber( Math.abs( range.getBBox().c1 - range.getBBox().c2 ) + 1 ); return this.value = new cNumber( Math.abs( range.getBBox().c1 - range.getBBox().c2 ) + 1 );
} }
else if ( arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea3D ) {
var range = arg0.getRange(); var range = arg0.getRange();
if ( range.length > 1 ) if ( range.length > 1 )
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new CNumber( Math.abs( range[0].getBBox().c1 - range[0].getBBox().c2 ) + 1 ); return this.value = new cNumber( Math.abs( range[0].getBBox().c1 - range[0].getBBox().c2 ) + 1 );
} }
else else
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
cCOLUMNS.prototype.getInfo = function () { cCOLUMNS.prototype.getInfo = function () {
return { return {
...@@ -321,20 +321,20 @@ function cHLOOKUP() { ...@@ -321,20 +321,20 @@ function cHLOOKUP() {
} }
cHLOOKUP.prototype = Object.create( cBaseFunction.prototype ) cHLOOKUP.prototype = Object.create( cBaseFunction.prototype )
cHLOOKUP.prototype.Calculate = function ( arg ) { cHLOOKUP.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = this.argumentsCurrent == 4 ? arg[3].tocBool() : new CBool( true ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = this.argumentsCurrent == 4 ? arg[3].tocBool() : new cBool( true );
var numberRow = arg2.getValue() - 1, valueForSearching = arg0.getValue(), resC = -1, min, regexp; var numberRow = arg2.getValue() - 1, valueForSearching = arg0.getValue(), resC = -1, min, regexp;
if ( isNaN( numberRow ) ) if ( isNaN( numberRow ) )
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
if ( numberRow < 0 ) if ( numberRow < 0 )
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
if ( arg0 instanceof CString ) { if ( arg0 instanceof cString ) {
valueForSearching = arg0.getValue(); valueForSearching = arg0.getValue();
regexp = searchRegExp( valueForSearching ); regexp = searchRegExp( valueForSearching );
} }
else if ( arg0 instanceof CError ) else if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
else { else {
valueForSearching = arg0.getValue(); valueForSearching = arg0.getValue();
...@@ -342,13 +342,13 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -342,13 +342,13 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
var found = false, bb; var found = false, bb;
if ( arg1 instanceof CRef || arg1 instanceof CRef3D || arg1 instanceof CArea ) { if ( arg1 instanceof cRef || arg1 instanceof cRef3D || arg1 instanceof cArea ) {
var range = arg1.getRange(), ws = arg1.getWS(); var range = arg1.getRange(), ws = arg1.getWS();
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberRow > bb.r2 - bb.r1 ) if ( numberRow > bb.r2 - bb.r1 )
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2);
var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value); var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache) if(oCache)
{ {
resC = oCache.index; resC = oCache.index;
...@@ -356,14 +356,14 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -356,14 +356,14 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
} }
// range._foreachColNoEmpty( /*func for col*/ null, /*func for cell in col*/ f ); // range._foreachColNoEmpty( /*func for col*/ null, /*func for cell in col*/ f );
} }
else if ( arg1 instanceof CArea3D ) { else if ( arg1 instanceof cArea3D ) {
var range = arg1.getRange()[0], ws = arg1.getWS() var range = arg1.getRange()[0], ws = arg1.getWS()
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberRow > bb.r2 - bb.r1 ) if ( numberRow > bb.r2 - bb.r1 )
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2);
var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value); var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache) if(oCache)
{ {
resC = oCache.index; resC = oCache.index;
...@@ -372,7 +372,7 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -372,7 +372,7 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
// range._foreachColNoEmpty( /*func for col*/ null, /*func for cell in col*/ f ); // range._foreachColNoEmpty( /*func for col*/ null, /*func for cell in col*/ f );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1.foreach( function ( elem, r, c ) { arg1.foreach( function ( elem, r, c ) {
if ( c == 0 ) if ( c == 0 )
min = elem.getValue(); min = elem.getValue();
...@@ -387,7 +387,7 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -387,7 +387,7 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
} }
} }
else { else {
if ( arg0 instanceof CString ) { if ( arg0 instanceof cString ) {
if ( regexp.test( elem.getValue() ) ) if ( regexp.test( elem.getValue() ) )
resC = c; resC = c;
} }
...@@ -400,15 +400,15 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -400,15 +400,15 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
} ) } )
if ( min > valueForSearching ) { if ( min > valueForSearching ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
if ( resC == -1 ) { if ( resC == -1 ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
if ( numberRow > arg1.getRowCount() - 1 ) { if ( numberRow > arg1.getRowCount() - 1 ) {
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
return this.value = arg1.getElementRowCol( numberRow, resC ); return this.value = arg1.getElementRowCol( numberRow, resC );
...@@ -416,11 +416,11 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -416,11 +416,11 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
} }
if ( min > valueForSearching ) { if ( min > valueForSearching ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
if ( resC == -1 ) { if ( resC == -1 ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
var c = new CellAddress( bb.r1 + numberRow, resC, 0 ); var c = new CellAddress( bb.r1 + numberRow, resC, 0 );
...@@ -464,15 +464,15 @@ function cINDEX() { ...@@ -464,15 +464,15 @@ function cINDEX() {
cINDEX.prototype = Object.create( cBaseFunction.prototype ) cINDEX.prototype = Object.create( cBaseFunction.prototype )
cINDEX.prototype.Calculate = function ( arg ) { cINDEX.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], var arg0 = arg[0],
arg1 = arg[1] && !(arg[1] instanceof CEmpty) ? arg[1] : new CNumber(1), arg1 = arg[1] && !(arg[1] instanceof cEmpty) ? arg[1] : new cNumber(1),
arg2 = arg[2] && !(arg[2] instanceof CEmpty) ? arg[2] : new CNumber(1), arg2 = arg[2] && !(arg[2] instanceof cEmpty) ? arg[2] : new cNumber(1),
arg3 = arg[3] && !(arg[3] instanceof CEmpty) ? arg[3] : new CNumber(1), arg3 = arg[3] && !(arg[3] instanceof cEmpty) ? arg[3] : new cNumber(1),
isArrayForm = false, res; isArrayForm = false, res;
if( arg0 instanceof CArea3D ){ if( arg0 instanceof cArea3D ){
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
else if( arg0 instanceof CError ){ else if( arg0 instanceof cError ){
return this.value = arg0; return this.value = arg0;
} }
...@@ -480,18 +480,18 @@ cINDEX.prototype.Calculate = function ( arg ) { ...@@ -480,18 +480,18 @@ cINDEX.prototype.Calculate = function ( arg ) {
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
arg3 = arg3.tocNumber(); arg3 = arg3.tocNumber();
if( arg1 instanceof CError || arg2 instanceof CError || arg3 instanceof CError ){ if( arg1 instanceof cError || arg2 instanceof cError || arg3 instanceof cError ){
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
if( arg1.getValue() < 0 || arg2.getValue() < 0 ){ if( arg1.getValue() < 0 || arg2.getValue() < 0 ){
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
if( arg0 instanceof CArray ){ if( arg0 instanceof cArray ){
arg0 = arg0.getMatrix(); arg0 = arg0.getMatrix();
} }
else if( arg0 instanceof CArea ){ else if( arg0 instanceof cArea ){
arg0 = arg0.getMatrix(); arg0 = arg0.getMatrix();
} }
else{ else{
...@@ -502,7 +502,7 @@ cINDEX.prototype.Calculate = function ( arg ) { ...@@ -502,7 +502,7 @@ cINDEX.prototype.Calculate = function ( arg ) {
if( res ) if( res )
res = res[arg2.getValue()-1]; res = res[arg2.getValue()-1];
return this.value = res ? res : new CError( cErrorType.bad_reference ); return this.value = res ? res : new cError( cErrorType.bad_reference );
} }
cINDEX.prototype.getInfo = function () { cINDEX.prototype.getInfo = function () {
...@@ -532,48 +532,48 @@ function cINDIRECT() { ...@@ -532,48 +532,48 @@ function cINDIRECT() {
} }
cINDIRECT.prototype = Object.create( cBaseFunction.prototype ) cINDIRECT.prototype = Object.create( cBaseFunction.prototype )
cINDIRECT.prototype.Calculate = function ( arg ) { cINDIRECT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tocString(), arg1 = arg[1] ? arg[1] : new CBool( true ), r = arguments[1], wb = r.worksheet.workbook, o = { Formula:"", pCurrPos:0 }, ref, found_operand; var arg0 = arg[0].tocString(), arg1 = arg[1] ? arg[1] : new cBool( true ), r = arguments[1], wb = r.worksheet.workbook, o = { Formula:"", pCurrPos:0 }, ref, found_operand;
function parseReference() { function parseReference() {
if ( (ref = parserHelp.is3DRef.call( o, o.Formula, o.pCurrPos ))[0] ) { if ( (ref = parserHelp.is3DRef.call( o, o.Formula, o.pCurrPos ))[0] ) {
var _wsFrom = ref[1], var _wsFrom = ref[1],
_wsTo = ( (ref[2] !== null) && (ref[2] !== undefined) ) ? ref[2] : _wsFrom; _wsTo = ( (ref[2] !== null) && (ref[2] !== undefined) ) ? ref[2] : _wsFrom;
if ( !(wb.getWorksheetByName( _wsFrom ) && wb.getWorksheetByName( _wsTo )) ) { if ( !(wb.getWorksheetByName( _wsFrom ) && wb.getWorksheetByName( _wsTo )) ) {
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) { if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) {
found_operand = new CArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb ); found_operand = new cArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb );
if ( o.operand_str.indexOf( "$" ) > -1 ) if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true; found_operand.isAbsolute = true;
} }
else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos ) ) { else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos ) ) {
if ( _wsTo != _wsFrom ) { if ( _wsTo != _wsFrom ) {
found_operand = new CArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb ); found_operand = new cArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb );
} }
else { else {
found_operand = new CRef3D( o.operand_str.toUpperCase(), _wsFrom, wb ); found_operand = new cRef3D( o.operand_str.toUpperCase(), _wsFrom, wb );
} }
if ( o.operand_str.indexOf( "$" ) > -1 ) if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true; found_operand.isAbsolute = true;
} }
} }
else if ( parserHelp.isName.call( o, o.Formula, o.pCurrPos, wb )[0] ) { else if ( parserHelp.isName.call( o, o.Formula, o.pCurrPos, wb )[0] ) {
found_operand = new CName( o.operand_str, wb ); found_operand = new cName( o.operand_str, wb );
} }
else if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) { else if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) {
found_operand = new CArea( o.operand_str.toUpperCase(), r.worksheet ); found_operand = new cArea( o.operand_str.toUpperCase(), r.worksheet );
if ( o.operand_str.indexOf( "$" ) > -1 ) if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true; found_operand.isAbsolute = true;
} }
else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos, true ) ) { else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos, true ) ) {
found_operand = new CRef( o.operand_str.toUpperCase(), r.worksheet ); found_operand = new cRef( o.operand_str.toUpperCase(), r.worksheet );
if ( o.operand_str.indexOf( "$" ) > -1 ) if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true; found_operand.isAbsolute = true;
} }
} }
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
var ret = new CArray(); var ret = new cArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
o = { Formula:elem.toString(), pCurrPos:0 }; o = { Formula:elem.toString(), pCurrPos:0 };
parseReference(); parseReference();
...@@ -589,12 +589,12 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -589,12 +589,12 @@ 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();
if ( (found_operand instanceof CRef || found_operand instanceof CRef3D || found_operand instanceof CArea) && found_operand.isValid() ) { if ( (found_operand instanceof cRef || found_operand instanceof cRef3D || found_operand instanceof cArea) && found_operand.isValid() ) {
var nFrom = wb.dependencyFormulas.addNode( wsId, cellName ), var nFrom = wb.dependencyFormulas.addNode( wsId, cellName ),
nTo = wb.dependencyFormulas.addNode( found_operand.getWsId(), found_operand._cells ); nTo = wb.dependencyFormulas.addNode( found_operand.getWsId(), found_operand._cells );
...@@ -602,7 +602,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -602,7 +602,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
wb.dependencyFormulas.addEdge2( nFrom, nTo ); wb.dependencyFormulas.addEdge2( nFrom, nTo );
} }
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, "" ) );
...@@ -611,7 +611,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -611,7 +611,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
return this.value = found_operand; return this.value = found_operand;
} }
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
cINDIRECT.prototype.getInfo = function () { cINDIRECT.prototype.getInfo = function () {
...@@ -644,10 +644,10 @@ cLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -644,10 +644,10 @@ cLOOKUP.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = this.argumentsCurrent == 2 ? arg1 : arg[2], var arg0 = arg[0], arg1 = arg[1], arg2 = this.argumentsCurrent == 2 ? arg1 : arg[2],
resC = -1, resR = -1; resC = -1, resR = -1;
if ( arg0 instanceof CError ) { if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
if ( arg0 instanceof CRef ) { if ( arg0 instanceof cRef ) {
arg0 = arg0.tryConvert(); arg0 = arg0.tryConvert();
} }
...@@ -666,42 +666,42 @@ cLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -666,42 +666,42 @@ cLOOKUP.prototype.Calculate = function ( arg ) {
} }
} }
if ( !( arg1 instanceof CArea || arg1 instanceof CArea3D || arg1 instanceof CArray || arg2 instanceof CArea || arg2 instanceof CArea3D || arg2 instanceof CArray) ) { if ( !( arg1 instanceof cArea || arg1 instanceof cArea3D || arg1 instanceof cArray || arg2 instanceof cArea || arg2 instanceof cArea3D || arg2 instanceof cArray) ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
if ( arg1 instanceof CArray && arg2 instanceof CArray ) { if ( arg1 instanceof cArray && arg2 instanceof cArray ) {
if ( arg1.getRowCount() != arg2.getRowCount() && arg1.getCountElementInRow() != arg2.getCountElementInRow() ) { if ( arg1.getRowCount() != arg2.getRowCount() && arg1.getCountElementInRow() != arg2.getCountElementInRow() ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
arrFinder( arg1 ); arrFinder( arg1 );
if ( resR <= -1 && resC <= -1 || resR <= -2 || resC <= -2 ) { if ( resR <= -1 && resC <= -1 || resR <= -2 || resC <= -2 ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
return this.value = arg2.getElementRowCol( resR, resC ); return this.value = arg2.getElementRowCol( resR, resC );
} }
else if ( arg1 instanceof CArray || arg2 instanceof CArray ) { else if ( arg1 instanceof cArray || arg2 instanceof cArray ) {
var _arg1, _arg2; var _arg1, _arg2;
_arg1 = arg1 instanceof CArray ? arg1 : arg2; _arg1 = arg1 instanceof cArray ? arg1 : arg2;
_arg2 = arg2 instanceof CArray ? arg1 : arg2; _arg2 = arg2 instanceof cArray ? arg1 : arg2;
var BBox = _arg2.getBBox(); var BBox = _arg2.getBBox();
if ( _arg1.getRowCount() != (BBox.r2 - BBox.r1) && _arg1.getCountElementInRow() != (BBox.c2 - BBox.c1) ) { if ( _arg1.getRowCount() != (BBox.r2 - BBox.r1) && _arg1.getCountElementInRow() != (BBox.c2 - BBox.c1) ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
arrFinder( _arg1 ); arrFinder( _arg1 );
if ( resR <= -1 && resC <= -1 || resR <= -2 || resC <= -2 ) { if ( resR <= -1 && resC <= -1 || resR <= -2 || resC <= -2 ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
var c = new CellAddress( BBox.r1 + resR, BBox.c1 + resC ) var c = new CellAddress( BBox.r1 + resR, BBox.c1 + resC )
...@@ -712,23 +712,23 @@ cLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -712,23 +712,23 @@ cLOOKUP.prototype.Calculate = function ( arg ) {
else { else {
var arg1Range = arg1.getRange(), arg2Range = arg2.getRange(); var arg1Range = arg1.getRange(), arg2Range = arg2.getRange();
if ( arg1 instanceof CArea3D && arg1Range.length > 1 || arg2 instanceof CArea3D && arg2Range.length > 1 ) if ( arg1 instanceof cArea3D && arg1Range.length > 1 || arg2 instanceof cArea3D && arg2Range.length > 1 )
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
if ( arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea3D ) {
arg1Range = arg1.getMatrix()[0]; arg1Range = arg1.getMatrix()[0];
// arg1Range = arg1Range[0]; // arg1Range = arg1Range[0];
} }
else if ( arg1 instanceof CArea ) { else if ( arg1 instanceof cArea ) {
arg1Range = arg1.getMatrix(); arg1Range = arg1.getMatrix();
} }
if ( arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea3D ) {
arg2Range = arg2.getMatrix()[0]; arg2Range = arg2.getMatrix()[0];
// arg2Range = arg2Range[0]; // arg2Range = arg2Range[0];
} }
else if ( arg2 instanceof CArea ) { else if ( arg2 instanceof cArea ) {
arg2Range = arg2.getMatrix(); arg2Range = arg2.getMatrix();
} }
...@@ -741,22 +741,22 @@ cLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -741,22 +741,22 @@ cLOOKUP.prototype.Calculate = function ( arg ) {
}() ) }() )
if ( index < 0 ) return this.value = new CError( cErrorType.not_available ); if ( index < 0 ) return this.value = new cError( cErrorType.not_available );
if ( this.argumentsCurrent == 2 ) { if ( this.argumentsCurrent == 2 ) {
if ( arg1Range[0].length >= 2 ) { if ( arg1Range[0].length >= 2 ) {
var b = arg1.getBBox(); var b = arg1.getBBox();
return this.value = new CRef( arg1.ws.getCell3( (b.r1 - 1) + index, (b.c1 - 1) + 1 ).getName(), arg1.ws ); return this.value = new cRef( arg1.ws.getCell3( (b.r1 - 1) + index, (b.c1 - 1) + 1 ).getName(), arg1.ws );
} }
else else
return this.value = new CRef( arg1.ws.getCell3( (b.r1 - 1) + 0, (b.c1 - 1) + index ).getName(), arg1.ws ); return this.value = new cRef( arg1.ws.getCell3( (b.r1 - 1) + 0, (b.c1 - 1) + index ).getName(), arg1.ws );
} }
else { else {
var b = arg2.getBBox(); var b = arg2.getBBox();
if ( arg2Range.length == 1 ) { if ( arg2Range.length == 1 ) {
return this.value = new CRef( arg1.ws.getCell3( (b.r1 - 1) + 0, (b.c1 - 1) + index ).getName(), arg1.ws ); return this.value = new cRef( arg1.ws.getCell3( (b.r1 - 1) + 0, (b.c1 - 1) + index ).getName(), arg1.ws );
} }
else else
return this.value = new CRef( arg1.ws.getCell3( (b.r1 - 1) + index, (b.c1 - 1) + 0 ).getName(), arg1.ws ); return this.value = new cRef( arg1.ws.getCell3( (b.r1 - 1) + index, (b.c1 - 1) + 0 ).getName(), arg1.ws );
} }
return this.value = arg2.getValue()[index]; return this.value = arg2.getValue()[index];
...@@ -788,16 +788,16 @@ function cMATCH() { ...@@ -788,16 +788,16 @@ function cMATCH() {
} }
cMATCH.prototype = Object.create( cBaseFunction.prototype ) cMATCH.prototype = Object.create( cBaseFunction.prototype )
cMATCH.prototype.Calculate = function ( arg ) { cMATCH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new CNumber(1); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber(1);
function findMatch(a0,a1,a2){ function findMatch(a0,a1,a2){
var a1RowCount = a1.length, a1ColumnCount = a1[0].length, var a1RowCount = a1.length, a1ColumnCount = a1[0].length,
a0Value = a0.getValue(), a2Value = a2.getValue(), a0Value = a0.getValue(), a2Value = a2.getValue(),
arr = [], res = new CError( cErrorType.not_available ), arr = [], res = new cError( cErrorType.not_available ),
index = -1; index = -1;
if( a1RowCount > 1 && a1ColumnCount > 1 ){ if( a1RowCount > 1 && a1ColumnCount > 1 ){
return new CError( cErrorType.not_available ); return new cError( cErrorType.not_available );
} }
else if( a1RowCount == 1 && a1ColumnCount > 1 ){ else if( a1RowCount == 1 && a1ColumnCount > 1 ){
for(var i = 0; i < a1ColumnCount; i++){ for(var i = 0; i < a1ColumnCount; i++){
...@@ -814,7 +814,7 @@ cMATCH.prototype.Calculate = function ( arg ) { ...@@ -814,7 +814,7 @@ cMATCH.prototype.Calculate = function ( arg ) {
} }
if( !(a2Value == 1 || a2Value == 0 || a2Value == -1) ){ if( !(a2Value == 1 || a2Value == 0 || a2Value == -1) ){
return new CError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
} }
if( a2Value == -1 ){ if( a2Value == -1 ){
...@@ -827,7 +827,7 @@ cMATCH.prototype.Calculate = function ( arg ) { ...@@ -827,7 +827,7 @@ cMATCH.prototype.Calculate = function ( arg ) {
} }
} }
else if( a2Value == 0 ){ else if( a2Value == 0 ){
if( a0 instanceof CString ){ if( a0 instanceof cString ){
for(var i = 0; i<arr.length; i++){ for(var i = 0; i<arr.length; i++){
if( searchRegExp2(arr[i].toString(),a0Value) ){ if( searchRegExp2(arr[i].toString(),a0Value) ){
index = i; index = i;
...@@ -853,37 +853,37 @@ cMATCH.prototype.Calculate = function ( arg ) { ...@@ -853,37 +853,37 @@ cMATCH.prototype.Calculate = function ( arg ) {
} }
if( index > -1 ) if( index > -1 )
res = new CNumber(index+1); res = new cNumber(index+1);
return res; return res;
} }
if( arg0 instanceof CArea3D || arg0 instanceof CArray || arg0 instanceof CArea ){ if( arg0 instanceof cArea3D || arg0 instanceof cArray || arg0 instanceof cArea ){
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
else if( arg0 instanceof CError ){ else if( arg0 instanceof cError ){
return this.value = arg0; return this.value = arg0;
} }
/* else{ /* else{
}*/ }*/
if( !(arg1 instanceof CArray || arg1 instanceof CArea) ){ if( !(arg1 instanceof cArray || arg1 instanceof cArea) ){
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
else { else {
arg1 = arg1.getMatrix(); arg1 = arg1.getMatrix();
} }
if( arg2 instanceof CNumber || arg2 instanceof CBool ){ if( arg2 instanceof cNumber || arg2 instanceof cBool ){
} }
else if( arg2 instanceof CError ){ else if( arg2 instanceof cError ){
return this.value = arg2; return this.value = arg2;
} }
else{ else{
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
return this.value = findMatch(arg0,arg1,arg2) return this.value = findMatch(arg0,arg1,arg2)
...@@ -914,7 +914,7 @@ function cOFFSET() { ...@@ -914,7 +914,7 @@ 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); 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);
if(1){} if(1){}
...@@ -949,27 +949,27 @@ cROW.prototype.Calculate = function ( arg ) { ...@@ -949,27 +949,27 @@ cROW.prototype.Calculate = function ( arg ) {
var arg0; var arg0;
if ( this.argumentsCurrent == 0 ) { if ( this.argumentsCurrent == 0 ) {
arg0 = arguments[1]; arg0 = arguments[1];
return this.value = new CNumber( arg0.getFirst().getRow() ); return this.value = new cNumber( arg0.getFirst().getRow() );
} }
arg0 = arg[0]; arg0 = arg[0];
if ( arg0 instanceof CRef || arg0 instanceof CRef3D || arg0 instanceof CArea ) { if ( arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea ) {
var range = arg0.getRange(); var range = arg0.getRange();
if ( range ) if ( range )
return this.value = new CNumber( range.getFirst().getRow() ); return this.value = new cNumber( range.getFirst().getRow() );
else else
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
else if ( arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea3D ) {
var r = arg0.getRange(); var r = arg0.getRange();
if ( r && r[0] && r[0].getFirst() ) { if ( r && r[0] && r[0].getFirst() ) {
return this.value = new CNumber( r[0].getFirst().getRow() ); return this.value = new cNumber( r[0].getFirst().getRow() );
} }
else { else {
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
} }
else else
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
cROW.prototype.getInfo = function () { cROW.prototype.getInfo = function () {
return { return {
...@@ -999,22 +999,22 @@ function cROWS() { ...@@ -999,22 +999,22 @@ function cROWS() {
cROWS.prototype = Object.create( cBaseFunction.prototype ) cROWS.prototype = Object.create( cBaseFunction.prototype )
cROWS.prototype.Calculate = function ( arg ) { cROWS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
return this.value = new CNumber( arg0.getRowCount() ); return this.value = new cNumber( arg0.getRowCount() );
} }
else if ( arg0 instanceof CArea || arg0 instanceof CRef || arg0 instanceof CRef3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cRef || arg0 instanceof cRef3D ) {
var range = arg0.getRange(); var range = arg0.getRange();
return this.value = new CNumber( Math.abs( range.getBBox().r1 - range.getBBox().r2 ) + 1 ); return this.value = new cNumber( Math.abs( range.getBBox().r1 - range.getBBox().r2 ) + 1 );
} }
else if ( arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea3D ) {
var range = arg0.getRange(); var range = arg0.getRange();
if ( range.length > 1 ) if ( range.length > 1 )
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new CNumber( Math.abs( range[0].getBBox().r1 - range[0].getBBox().r2 ) + 1 ); return this.value = new cNumber( Math.abs( range[0].getBBox().r1 - range[0].getBBox().r2 ) + 1 );
} }
else else
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
cROWS.prototype.getInfo = function () { cROWS.prototype.getInfo = function () {
return { return {
...@@ -1049,7 +1049,7 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) { ...@@ -1049,7 +1049,7 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) {
function TransposeMatrix( A ) { function TransposeMatrix( A ) {
var tMatrix = [], res = new CArray(); var tMatrix = [], res = new cArray();
for ( var i = 0; i < A.length; i++ ) { for ( var i = 0; i < A.length; i++ ) {
for ( var j = 0; j < A[i].length; j++ ) { for ( var j = 0; j < A[i].length; j++ ) {
...@@ -1064,17 +1064,17 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) { ...@@ -1064,17 +1064,17 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) {
} }
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArray ) { if ( arg0 instanceof cArea || arg0 instanceof cArray ) {
arg0 = arg0.getMatrix(); arg0 = arg0.getMatrix();
} }
else if( arg0 instanceof CNumber || arg0 instanceof CString || arg0 instanceof CBool || arg0 instanceof CRef || arg0 instanceof CRef3D ){ else if( arg0 instanceof cNumber || arg0 instanceof cString || arg0 instanceof cBool || arg0 instanceof cRef || arg0 instanceof cRef3D ){
return this.value = arg0.getValue(); return this.value = arg0.getValue();
} }
else if( arg0 instanceof CError ){ else if( arg0 instanceof cError ){
return this.value = arg0; return this.value = arg0;
} }
else else
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
return this.value = TransposeMatrix( arg0 ); return this.value = TransposeMatrix( arg0 );
...@@ -1141,7 +1141,7 @@ VHLOOKUPCache.prototype._calculate = function(cacheArray, valueForSearching, isV ...@@ -1141,7 +1141,7 @@ VHLOOKUPCache.prototype._calculate = function(cacheArray, valueForSearching, isV
} }
if ( arg3Value == true ) { if ( arg3Value == true ) {
if ( isValueString ) { if ( isValueString ) {
if ( cvType instanceof CString ) { if ( cvType instanceof cString ) {
if ( valueForSearching.localeCompare( cvType.getValue() ) == 0 ) { if ( valueForSearching.localeCompare( cvType.getValue() ) == 0 ) {
res.index = index; res.index = index;
found = true; found = true;
...@@ -1212,23 +1212,23 @@ function cVLOOKUP() { ...@@ -1212,23 +1212,23 @@ function cVLOOKUP() {
} }
cVLOOKUP.prototype = Object.create( cBaseFunction.prototype ) cVLOOKUP.prototype = Object.create( cBaseFunction.prototype )
cVLOOKUP.prototype.Calculate = function ( arg ) { cVLOOKUP.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = this.argumentsCurrent == 4 ? arg[3].tocBool() : new CBool( true ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = this.argumentsCurrent == 4 ? arg[3].tocBool() : new cBool( true );
var numberCol = arg2.getValue() - 1, valueForSearching, resR = -1, min, regexp; var numberCol = arg2.getValue() - 1, valueForSearching, resR = -1, min, regexp;
if ( isNaN( numberCol ) ) if ( isNaN( numberCol ) )
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
if ( numberCol < 0 ) if ( numberCol < 0 )
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
if ( arg0 instanceof CRef ) { if ( arg0 instanceof cRef ) {
arg0 = arg0.getValue() arg0 = arg0.getValue()
} }
if ( arg0 instanceof CString ) { if ( arg0 instanceof cString ) {
valueForSearching = arg0.getValue(); valueForSearching = arg0.getValue();
} }
else if ( arg0 instanceof CError ) else if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
else { else {
valueForSearching = arg0.getValue(); valueForSearching = arg0.getValue();
...@@ -1236,27 +1236,27 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1236,27 +1236,27 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
var found = false, bb; var found = false, bb;
if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) { if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
var range = arg1.getRange(), ws = arg1.getWS(); var range = arg1.getRange(), ws = arg1.getWS();
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberCol > bb.c2 - bb.c1 ) if ( numberCol > bb.c2 - bb.c1 )
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1);
var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value); var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache) if(oCache)
{ {
resR = oCache.index; resR = oCache.index;
min = oCache.min; min = oCache.min;
} }
} }
else if ( arg1 instanceof CArea ) { else if ( arg1 instanceof cArea ) {
var range = arg1.getRange(), ws = arg1.getWS(); var range = arg1.getRange(), ws = arg1.getWS();
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberCol > bb.c2 - bb.c1 ) if ( numberCol > bb.c2 - bb.c1 )
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1);
var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value); var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache) if(oCache)
{ {
resR = oCache.index; resR = oCache.index;
...@@ -1305,11 +1305,11 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1305,11 +1305,11 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} }
}*/ }*/
} }
else if ( arg1 instanceof CArea3D ) { else if ( arg1 instanceof cArea3D ) {
var range = arg1.getRange()[0], ws = arg1.getWS(); var range = arg1.getRange()[0], ws = arg1.getWS();
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberCol > bb.c2 - bb.c1 ) if ( numberCol > bb.c2 - bb.c1 )
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
/*var matrix = arg1.getMatrix()[0] /*var matrix = arg1.getMatrix()[0]
...@@ -1355,7 +1355,7 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1355,7 +1355,7 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
}*/ }*/
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1);
var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value); var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache) if(oCache)
{ {
resR = oCache.index; resR = oCache.index;
...@@ -1363,8 +1363,8 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1363,8 +1363,8 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} }
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
if(arg0 instanceof CString) if(arg0 instanceof cString)
regexp = searchRegExp( valueForSearching ); regexp = searchRegExp( valueForSearching );
arg1.foreach( function ( elem, r, c ) { arg1.foreach( function ( elem, r, c ) {
if ( r == 0 ) if ( r == 0 )
...@@ -1380,7 +1380,7 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1380,7 +1380,7 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} }
} }
else { else {
if ( arg0 instanceof CString ) { if ( arg0 instanceof cString ) {
if ( regexp.test( elem.getValue() ) ) if ( regexp.test( elem.getValue() ) )
resR = r; resR = r;
} }
...@@ -1393,15 +1393,15 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1393,15 +1393,15 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} ) } )
if ( min > valueForSearching ) { if ( min > valueForSearching ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
if ( resR == -1 ) { if ( resR == -1 ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
if ( numberCol > arg1.getCountElementInRow() - 1 ) { if ( numberCol > arg1.getCountElementInRow() - 1 ) {
return this.value = new CError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
return this.value = arg1.getElementRowCol( resR, numberCol ); return this.value = arg1.getElementRowCol( resR, numberCol );
...@@ -1409,11 +1409,11 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1409,11 +1409,11 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} }
if ( min > valueForSearching ) { if ( min > valueForSearching ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
if ( resR == -1 ) { if ( resR == -1 ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
var c = new CellAddress( resR, bb.c1 + numberCol, 0 ); var c = new CellAddress( resR, bb.c1 + numberCol, 0 );
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -77,31 +77,31 @@ cCHAR.prototype = Object.create( cBaseFunction.prototype ) ...@@ -77,31 +77,31 @@ cCHAR.prototype = Object.create( cBaseFunction.prototype )
cCHAR.prototype.Calculate = function ( arg ) { cCHAR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
var ret = new CArray(); var ret = new cArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocNumber(); var _elem = elem.tocNumber();
if ( !ret.array[r] ) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
if ( _elem instanceof CError ) if ( _elem instanceof cError )
ret.addElement( _elem ); ret.addElement( _elem );
else else
ret.addElement( new CString( String.fromCharCode( _elem.getValue() ) ) ); ret.addElement( new cString( String.fromCharCode( _elem.getValue() ) ) );
} ) } )
return this.value = ret; return this.value = ret;
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
if ( arg0 instanceof CError ) { if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
return this.value = new CString( String.fromCharCode( arg0.getValue() ) ); return this.value = new cString( String.fromCharCode( arg0.getValue() ) );
} }
cCHAR.prototype.getInfo = function () { cCHAR.prototype.getInfo = function () {
return { return {
...@@ -133,10 +133,10 @@ cCLEAN.prototype = Object.create( cBaseFunction.prototype ) ...@@ -133,10 +133,10 @@ cCLEAN.prototype = Object.create( cBaseFunction.prototype )
cCLEAN.prototype.Calculate = function ( arg ) { cCLEAN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
...@@ -149,7 +149,7 @@ cCLEAN.prototype.Calculate = function ( arg ) { ...@@ -149,7 +149,7 @@ cCLEAN.prototype.Calculate = function ( arg ) {
res += v[i]; res += v[i];
} }
return this.value = new CString( res ); return this.value = new cString( res );
} }
cCLEAN.prototype.getInfo = function () { cCLEAN.prototype.getInfo = function () {
return { return {
...@@ -180,31 +180,31 @@ cCODE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -180,31 +180,31 @@ cCODE.prototype = Object.create( cBaseFunction.prototype )
cCODE.prototype.Calculate = function ( arg ) { cCODE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
var ret = new CArray(); var ret = new cArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocString(); var _elem = elem.tocString();
if ( !ret.array[r] ) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
if ( _elem instanceof CError ) if ( _elem instanceof cError )
ret.addElement( _elem ); ret.addElement( _elem );
else else
ret.addElement( new CNumber( _elem.toString().charCodeAt() ) ); ret.addElement( new cNumber( _elem.toString().charCodeAt() ) );
} ) } )
return this.value = ret; return this.value = ret;
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CError ) { if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
return this.value = new CNumber( arg0.toString().charCodeAt() ); return this.value = new cNumber( arg0.toString().charCodeAt() );
} }
cCODE.prototype.getInfo = function () { cCODE.prototype.getInfo = function () {
return { return {
...@@ -233,32 +233,32 @@ function cCONCATENATE() { ...@@ -233,32 +233,32 @@ function cCONCATENATE() {
} }
cCONCATENATE.prototype = Object.create( cBaseFunction.prototype ) cCONCATENATE.prototype = Object.create( cBaseFunction.prototype )
cCONCATENATE.prototype.Calculate = function ( arg ) { cCONCATENATE.prototype.Calculate = function ( arg ) {
var arg0 = new CString( "" ), argI; var arg0 = new cString( "" ), argI;
for ( var i = 0; i < this.argumentsCurrent; i++ ) { for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i]; argI = arg[i];
if ( argI instanceof CArea || argI instanceof CArea3D ) { if ( argI instanceof cArea || argI instanceof cArea3D ) {
argI = argI.cross( arguments[1].first ); argI = argI.cross( arguments[1].first );
} }
argI = argI.tocString(); argI = argI.tocString();
if ( argI instanceof CError ) { if ( argI instanceof cError ) {
return this.value = argI; return this.value = argI;
} }
else if ( argI instanceof CArray ) { else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) { argI.foreach( function ( elem ) {
if ( elem instanceof CError ) { if ( elem instanceof cError ) {
arg0 = elem; arg0 = elem;
return true; return true;
} }
arg0 = new CString( arg0.toString().concat( elem.toString() ) ); arg0 = new cString( arg0.toString().concat( elem.toString() ) );
} ) } )
if ( arg0 instanceof CError ) { if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
} }
else else
arg0 = new CString( arg0.toString().concat( argI.toString() ) ); arg0 = new cString( arg0.toString().concat( argI.toString() ) );
} }
return this.value = arg0; return this.value = arg0;
}; };
...@@ -316,16 +316,16 @@ cDOLLAR.prototype.Calculate = function ( arg ) { ...@@ -316,16 +316,16 @@ cDOLLAR.prototype.Calculate = function ( arg ) {
if ( num_digits > cExcelMaxExponent ) { if ( num_digits > cExcelMaxExponent ) {
if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally
{ {
return new CNumber( number ); return new cNumber( number );
} }
return new CNumber( 0 ); return new cNumber( 0 );
} }
else if ( num_digits < cExcelMinExponent ) { else if ( num_digits < cExcelMinExponent ) {
if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally
{ {
return new CNumber( number ); return new cNumber( number );
} }
return new CNumber( 0 ); return new cNumber( 0 );
} }
var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) ); var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) );
...@@ -333,10 +333,10 @@ cDOLLAR.prototype.Calculate = function ( arg ) { ...@@ -333,10 +333,10 @@ cDOLLAR.prototype.Calculate = function ( arg ) {
number += significance / 2; number += significance / 2;
if ( number / significance == Infinity ) { if ( number / significance == Infinity ) {
return new CNumber( number ); return new cNumber( number );
} }
return new CNumber( Floor( number, significance ) ); return new cNumber( Floor( number, significance ) );
} }
function toFix( str, skip ) { function toFix( str, skip ) {
...@@ -366,80 +366,80 @@ cDOLLAR.prototype.Calculate = function ( arg ) { ...@@ -366,80 +366,80 @@ cDOLLAR.prototype.Calculate = function ( arg ) {
} }
var arg0 = arg[0], var arg0 = arg[0],
arg1 = arg[1] ? arg[1] : new CNumber( 2 ), arg1 = arg[1] ? arg[1] : new cNumber( 2 ),
arg2 = arg[2] ? arg[2] : new CBool( false ); arg2 = arg[2] ? arg[2] : new cBool( false );
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof CError ) return this.value = arg2; if ( arg2 instanceof cError ) return this.value = arg2;
if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
else if ( arg0 instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type ); else if ( arg0 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
} }
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) { if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
else if ( arg1 instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type ); else if ( arg1 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
} }
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
if ( arg0 instanceof CArray && arg1 instanceof CArray ) { if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) { if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
else { else {
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
var b = arg1.getElementRowCol( r, c ); var b = arg1.getElementRowCol( r, c );
if ( a instanceof CNumber && b instanceof CNumber ) { if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new CError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg0; return this.value = arg0;
} }
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
var b = arg1; var b = arg1;
if ( a instanceof CNumber && b instanceof CNumber ) { if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new CError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg0; return this.value = arg0;
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1.foreach( function ( elem, r, c ) { arg1.foreach( function ( elem, r, c ) {
var a = arg0; var a = arg0;
var b = elem; var b = elem;
if ( a instanceof CNumber && b instanceof CNumber ) { if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new CError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg1; return this.value = arg1;
} }
...@@ -456,7 +456,7 @@ cDOLLAR.prototype.Calculate = function ( arg ) { ...@@ -456,7 +456,7 @@ cDOLLAR.prototype.Calculate = function ( arg ) {
} }
} }
this.value = new CString( oNumFormatCache.get( "$#,##0" + cNull + ";($#,##0" + cNull + ")" ).format( roundHelper( number, num_digits ).getValue(), CellValueType.Number, gc_nMaxDigCount )[0].text ) this.value = new cString( oNumFormatCache.get( "$#,##0" + cNull + ";($#,##0" + cNull + ")" ).format( roundHelper( number, num_digits ).getValue(), CellValueType.Number, gc_nMaxDigCount )[0].text )
return this.value; return this.value;
} }
cDOLLAR.prototype.getInfo = function () { cDOLLAR.prototype.getInfo = function () {
...@@ -487,32 +487,32 @@ function cEXACT() { ...@@ -487,32 +487,32 @@ function cEXACT() {
cEXACT.prototype = Object.create( cBaseFunction.prototype ) cEXACT.prototype = Object.create( cBaseFunction.prototype )
cEXACT.prototype.Calculate = function ( arg ) { cEXACT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if ( arg0 instanceof CArray && arg1 instanceof CArray ) { if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
var arg0val = arg0.getValue(), arg1val = arg1.getValue(); var arg0val = arg0.getValue(), arg1val = arg1.getValue();
return this.value = new CBool( arg0val === arg1val ); return this.value = new cBool( arg0val === arg1val );
} }
cEXACT.prototype.getInfo = function () { cEXACT.prototype.getInfo = function () {
return { return {
...@@ -543,10 +543,10 @@ cFIND.prototype = Object.create( cBaseFunction.prototype ) ...@@ -543,10 +543,10 @@ cFIND.prototype = Object.create( cBaseFunction.prototype )
cFIND.prototype.Calculate = function ( arg ) { cFIND.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = this.getArguments() == 3 ? arg[2] : null, res, str, searchStr, pos = -1; var arg0 = arg[0], arg1 = arg[1], arg2 = this.getArguments() == 3 ? arg[2] : null, res, str, searchStr, pos = -1;
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
...@@ -555,29 +555,29 @@ cFIND.prototype.Calculate = function ( arg ) { ...@@ -555,29 +555,29 @@ cFIND.prototype.Calculate = function ( arg ) {
if ( arg2 !== null ) { if ( arg2 !== null ) {
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg2 instanceof CArray ) { if ( arg2 instanceof cArray ) {
arg2 = arg1.getElementRowCol( 0, 0 ); arg2 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof CError ) return this.value = arg2; if ( arg2 instanceof cError ) return this.value = arg2;
pos = arg2.getValue(); pos = arg2.getValue();
pos = pos > 0 ? pos - 1 : pos; pos = pos > 0 ? pos - 1 : pos;
} }
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArray ) { if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
str = arg1.getValue(); str = arg1.getValue();
searchStr = arg0.getValue(); searchStr = arg0.getValue();
...@@ -585,7 +585,7 @@ cFIND.prototype.Calculate = function ( arg ) { ...@@ -585,7 +585,7 @@ cFIND.prototype.Calculate = function ( arg ) {
if ( arg2 ) { if ( arg2 ) {
if ( pos > str.length || pos < 0 ) if ( pos > str.length || pos < 0 )
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
str = str.substring( pos ); str = str.substring( pos );
res = str.search( searchStr ); res = str.search( searchStr );
...@@ -596,9 +596,9 @@ cFIND.prototype.Calculate = function ( arg ) { ...@@ -596,9 +596,9 @@ cFIND.prototype.Calculate = function ( arg ) {
res = str.search( searchStr ); res = str.search( searchStr );
if ( res < 0 ) if ( res < 0 )
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new CNumber( res + 1 ); return this.value = new cNumber( res + 1 );
} }
cFIND.prototype.getInfo = function () { cFIND.prototype.getInfo = function () {
...@@ -660,16 +660,16 @@ cFIXED.prototype.Calculate = function ( arg ) { ...@@ -660,16 +660,16 @@ cFIXED.prototype.Calculate = function ( arg ) {
if ( num_digits > cExcelMaxExponent ) { if ( num_digits > cExcelMaxExponent ) {
if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally
{ {
return new CNumber( number ); return new cNumber( number );
} }
return new CNumber( 0 ); return new cNumber( 0 );
} }
else if ( num_digits < cExcelMinExponent ) { else if ( num_digits < cExcelMinExponent ) {
if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally
{ {
return new CNumber( number ); return new cNumber( number );
} }
return new CNumber( 0 ); return new cNumber( 0 );
} }
var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) ); var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) );
...@@ -677,10 +677,10 @@ cFIXED.prototype.Calculate = function ( arg ) { ...@@ -677,10 +677,10 @@ cFIXED.prototype.Calculate = function ( arg ) {
number += significance / 2; number += significance / 2;
if ( number / significance == Infinity ) { if ( number / significance == Infinity ) {
return new CNumber( number ); return new cNumber( number );
} }
return new CNumber( Floor( number, significance ) ); return new cNumber( Floor( number, significance ) );
} }
function toFix( str, skip ) { function toFix( str, skip ) {
...@@ -710,80 +710,80 @@ cFIXED.prototype.Calculate = function ( arg ) { ...@@ -710,80 +710,80 @@ cFIXED.prototype.Calculate = function ( arg ) {
} }
var arg0 = arg[0], var arg0 = arg[0],
arg1 = arg[1] ? arg[1] : new CNumber( 2 ), arg1 = arg[1] ? arg[1] : new cNumber( 2 ),
arg2 = arg[2] ? arg[2] : new CBool( false ); arg2 = arg[2] ? arg[2] : new cBool( false );
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof CError ) return this.value = arg2; if ( arg2 instanceof cError ) return this.value = arg2;
if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
else if ( arg0 instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type ); else if ( arg0 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
} }
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) { if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
else if ( arg1 instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type ); else if ( arg1 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
} }
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
if ( arg0 instanceof CArray && arg1 instanceof CArray ) { if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) { if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) {
return this.value = new CError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
else { else {
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
var b = arg1.getElementRowCol( r, c ); var b = arg1.getElementRowCol( r, c );
if ( a instanceof CNumber && b instanceof CNumber ) { if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new CError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg0; return this.value = arg0;
} }
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
var b = arg1; var b = arg1;
if ( a instanceof CNumber && b instanceof CNumber ) { if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new CError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg0; return this.value = arg0;
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1.foreach( function ( elem, r, c ) { arg1.foreach( function ( elem, r, c ) {
var a = arg0; var a = arg0;
var b = elem; var b = elem;
if ( a instanceof CNumber && b instanceof CNumber ) { if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new CError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg1; return this.value = arg1;
} }
...@@ -797,7 +797,7 @@ cFIXED.prototype.Calculate = function ( arg ) { ...@@ -797,7 +797,7 @@ cFIXED.prototype.Calculate = function ( arg ) {
for ( var i = 0; i < num_digits; i++, cNull += "0" ) { for ( var i = 0; i < num_digits; i++, cNull += "0" ) {
} }
} }
return this.value = new CString( oNumFormatCache.get( "#" + (arg2.toBool() ? "" : ",") + "##0" + cNull ).format( roundHelper( number, num_digits ).getValue(), CellValueType.Number, gc_nMaxDigCount )[0].text ) return this.value = new cString( oNumFormatCache.get( "#" + (arg2.toBool() ? "" : ",") + "##0" + cNull ).format( roundHelper( number, num_digits ).getValue(), CellValueType.Number, gc_nMaxDigCount )[0].text )
} }
cFIXED.prototype.getInfo = function () { cFIXED.prototype.getInfo = function () {
return { return {
...@@ -831,34 +831,34 @@ function cLEFT() { ...@@ -831,34 +831,34 @@ function cLEFT() {
} }
cLEFT.prototype = Object.create( cBaseFunction.prototype ) cLEFT.prototype = Object.create( cBaseFunction.prototype )
cLEFT.prototype.Calculate = function ( arg ) { cLEFT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new CNumber( 1 ) : arg[1]; var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof CArray && arg1 instanceof CArray ) { if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg1.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new CString( arg0.getValue().substring( 0, arg1.getValue() ) ) return this.value = new cString( arg0.getValue().substring( 0, arg1.getValue() ) )
} }
cLEFT.prototype.getInfo = function () { cLEFT.prototype.getInfo = function () {
...@@ -895,19 +895,19 @@ function cLEN() { ...@@ -895,19 +895,19 @@ function cLEN() {
cLEN.prototype = Object.create( cBaseFunction.prototype ) cLEN.prototype = Object.create( cBaseFunction.prototype )
cLEN.prototype.Calculate = function ( arg ) { cLEN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
return this.value = new CNumber( arg0.getValue().length ) return this.value = new cNumber( arg0.getValue().length )
} }
cLEN.prototype.getInfo = function () { cLEN.prototype.getInfo = function () {
...@@ -945,16 +945,16 @@ cLOWER.prototype = Object.create( cBaseFunction.prototype ) ...@@ -945,16 +945,16 @@ cLOWER.prototype = Object.create( cBaseFunction.prototype )
cLOWER.prototype.Calculate = function ( arg ) { cLOWER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) if ( arg0 instanceof cArea || arg0 instanceof cArea3D )
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CArray ) if ( arg0 instanceof cArray )
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
return this.value = new CString( arg0.getValue().toLowerCase() ); return this.value = new cString( arg0.getValue().toLowerCase() );
} }
cLOWER.prototype.getInfo = function () { cLOWER.prototype.getInfo = function () {
return { return {
...@@ -984,13 +984,13 @@ function cMID() { ...@@ -984,13 +984,13 @@ function cMID() {
cMID.prototype = Object.create( cBaseFunction.prototype ) cMID.prototype = Object.create( cBaseFunction.prototype )
cMID.prototype.Calculate = function ( arg ) { cMID.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
...@@ -998,31 +998,31 @@ cMID.prototype.Calculate = function ( arg ) { ...@@ -998,31 +998,31 @@ cMID.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg0 instanceof CArray ) { if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CArray ) { if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof CArray ) { if ( arg2 instanceof cArray ) {
arg2 = arg2.getElementRowCol( 0, 0 ); arg2 = arg2.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof CError ) return this.value = arg2; if ( arg2 instanceof cError ) return this.value = arg2;
if ( arg1.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
if ( arg2.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type ); if ( arg2.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
var l = arg0.getValue().length; var l = arg0.getValue().length;
if ( arg1.getValue() > l ) if ( arg1.getValue() > l )
return this.value = new CString( "" ); return this.value = new cString( "" );
/* if( arg1.getValue() < l ) /* if( arg1.getValue() < l )
return this.value = arg0; */ return this.value = arg0; */
return this.value = new CString( arg0.getValue().substr( arg1.getValue() == 0 ? 0 : arg1.getValue() - 1, arg2.getValue() ) ) return this.value = new cString( arg0.getValue().substr( arg1.getValue() == 0 ? 0 : arg1.getValue() - 1, arg2.getValue() ) )
} }
cMID.prototype.getInfo = function () { cMID.prototype.getInfo = function () {
...@@ -1087,31 +1087,31 @@ cPROPER.prototype.Calculate = function ( arg ) { ...@@ -1087,31 +1087,31 @@ cPROPER.prototype.Calculate = function ( arg ) {
return retStr; return retStr;
} }
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
var ret = new CArray(); var ret = new cArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocString(); var _elem = elem.tocString();
if ( !ret.array[r] ) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
if ( _elem instanceof CError ) if ( _elem instanceof cError )
ret.addElement( _elem ); ret.addElement( _elem );
else else
ret.addElement( new CString( proper( _elem.toString() ) ) ); ret.addElement( new cString( proper( _elem.toString() ) ) );
} ) } )
return this.value = ret; return this.value = ret;
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CError ) { if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
return this.value = new CString( proper( arg0.toString() ) ); return this.value = new cString( proper( arg0.toString() ) );
} }
cPROPER.prototype.getInfo = function () { cPROPER.prototype.getInfo = function () {
return { return {
...@@ -1142,53 +1142,53 @@ cREPLACE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1142,53 +1142,53 @@ cREPLACE.prototype = Object.create( cBaseFunction.prototype )
cREPLACE.prototype.Calculate = function ( arg ) { cREPLACE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocNumber(); arg1 = arg1.cross( arguments[1].first ).tocNumber();
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 ).tocNumber(); arg1 = arg1.getElement( 0 ).tocNumber();
} }
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ).tocNumber(); arg2 = arg2.cross( arguments[1].first ).tocNumber();
} }
else if ( arg2 instanceof CArray ) { else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement( 0 ).tocNumber(); arg2 = arg2.getElement( 0 ).tocNumber();
} }
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg3 instanceof CArea || arg3 instanceof CArea3D ) { if ( arg3 instanceof cArea || arg3 instanceof cArea3D ) {
arg3 = arg3.cross( arguments[1].first ).tocString(); arg3 = arg3.cross( arguments[1].first ).tocString();
} }
else if ( arg3 instanceof CArray ) { else if ( arg3 instanceof cArray ) {
arg3 = arg3.getElement( 0 ).tocString(); arg3 = arg3.getElement( 0 ).tocString();
} }
arg3 = arg3.tocString(); arg3 = arg3.tocString();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof CError ) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
if ( arg2 instanceof CError ) if ( arg2 instanceof cError )
return this.value = arg2; return this.value = arg2;
if ( arg3 instanceof CError ) if ( arg3 instanceof cError )
return this.value = arg3; return this.value = arg3;
if ( arg1.getValue() < 1 || arg2.getValue() < 0 ) { if ( arg1.getValue() < 1 || arg2.getValue() < 0 ) {
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
var string1 = arg0.getValue(), string2 = arg3.getValue(), res = ""; var string1 = arg0.getValue(), string2 = arg3.getValue(), res = "";
...@@ -1199,7 +1199,7 @@ cREPLACE.prototype.Calculate = function ( arg ) { ...@@ -1199,7 +1199,7 @@ cREPLACE.prototype.Calculate = function ( arg ) {
res += string1[i]; res += string1[i];
} }
return this.value = new CString( res ); return this.value = new cString( res );
} }
cREPLACE.prototype.getInfo = function () { cREPLACE.prototype.getInfo = function () {
...@@ -1236,48 +1236,48 @@ function cREPT() { ...@@ -1236,48 +1236,48 @@ function cREPT() {
cREPT.prototype = Object.create( cBaseFunction.prototype ) cREPT.prototype = Object.create( cBaseFunction.prototype )
cREPT.prototype.Calculate = function ( arg ) { cREPT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], res = ""; var arg0 = arg[0], arg1 = arg[1], res = "";
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg0 instanceof CArray && arg1 instanceof CArray ) { if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocNumber(); arg1 = arg1.cross( arguments[1].first ).tocNumber();
} }
else if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) { else if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
} }
if ( arg1 instanceof CError ) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
else if ( arg1 instanceof CString ) else if ( arg1 instanceof cString )
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
else else
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg1.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
for ( var i = 0; i < arg1.getValue(); i++ ) { for ( var i = 0; i < arg1.getValue(); i++ ) {
res = res.concat( arg0.getValue() ); res = res.concat( arg0.getValue() );
} }
return this.value = new CString( res ); return this.value = new cString( res );
} }
cREPT.prototype.getInfo = function () { cREPT.prototype.getInfo = function () {
return { return {
...@@ -1306,34 +1306,34 @@ function cRIGHT() { ...@@ -1306,34 +1306,34 @@ function cRIGHT() {
} }
cRIGHT.prototype = Object.create( cBaseFunction.prototype ) cRIGHT.prototype = Object.create( cBaseFunction.prototype )
cRIGHT.prototype.Calculate = function ( arg ) { cRIGHT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new CNumber( 1 ) : arg[1]; var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof CArray && arg1 instanceof CArray ) { if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg1.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
var l = arg0.getValue().length, _number = l - arg1.getValue(); var l = arg0.getValue().length, _number = l - arg1.getValue();
return this.value = new CString( arg0.getValue().substring( _number < 0 ? 0 : _number, l ) ) return this.value = new cString( arg0.getValue().substring( _number < 0 ? 0 : _number, l ) )
} }
cRIGHT.prototype.getInfo = function () { cRIGHT.prototype.getInfo = function () {
...@@ -1370,44 +1370,44 @@ function cSEARCH() { ...@@ -1370,44 +1370,44 @@ function cSEARCH() {
cSEARCH.prototype = Object.create( cBaseFunction.prototype ) cSEARCH.prototype = Object.create( cBaseFunction.prototype )
cSEARCH.prototype.Calculate = function ( arg ) { cSEARCH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new CNumber( 1 ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber( 1 );
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocString(); arg1 = arg1.cross( arguments[1].first ).tocString();
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 ).tocString(); arg1 = arg1.getElement( 0 ).tocString();
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ).tocNumber(); arg2 = arg2.cross( arguments[1].first ).tocNumber();
} }
else if ( arg2 instanceof CArray ) { else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement( 0 ).tocNumber(); arg2 = arg2.getElement( 0 ).tocNumber();
} }
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof CError ) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
if ( arg2 instanceof CError ) if ( arg2 instanceof cError )
return this.value = arg2; return this.value = arg2;
if ( arg2.getValue() < 1 || arg2.getValue() > arg1.getValue().length ) { if ( arg2.getValue() < 1 || arg2.getValue() > arg1.getValue().length ) {
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
var string1 = arg0.getValue(), string2 = arg1.getValue(), var string1 = arg0.getValue(), string2 = arg1.getValue(),
...@@ -1437,9 +1437,9 @@ cSEARCH.prototype.Calculate = function ( arg ) { ...@@ -1437,9 +1437,9 @@ cSEARCH.prototype.Calculate = function ( arg ) {
var res = string2.substring( arg2.getValue() - 1 ).search( valueForSearching ) + arg2.getValue() - 1; var res = string2.substring( arg2.getValue() - 1 ).search( valueForSearching ) + arg2.getValue() - 1;
if ( res < 0 ) if ( res < 0 )
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new CNumber( res + 1 ); return this.value = new cNumber( res + 1 );
} }
cSEARCH.prototype.getInfo = function () { cSEARCH.prototype.getInfo = function () {
...@@ -1475,55 +1475,55 @@ function cSUBSTITUTE() { ...@@ -1475,55 +1475,55 @@ function cSUBSTITUTE() {
} }
cSUBSTITUTE.prototype = Object.create( cBaseFunction.prototype ) cSUBSTITUTE.prototype = Object.create( cBaseFunction.prototype )
cSUBSTITUTE.prototype.Calculate = function ( arg ) { cSUBSTITUTE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new CNumber( 0 ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new cNumber( 0 );
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocString(); arg1 = arg1.cross( arguments[1].first ).tocString();
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 ).tocString(); arg1 = arg1.getElement( 0 ).tocString();
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) { if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ).tocString(); arg2 = arg2.cross( arguments[1].first ).tocString();
} }
else if ( arg2 instanceof CArray ) { else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement( 0 ).tocString(); arg2 = arg2.getElement( 0 ).tocString();
} }
arg2 = arg2.tocString(); arg2 = arg2.tocString();
if ( arg3 instanceof CArea || arg3 instanceof CArea3D ) { if ( arg3 instanceof cArea || arg3 instanceof cArea3D ) {
arg3 = arg3.cross( arguments[1].first ).tocNumber(); arg3 = arg3.cross( arguments[1].first ).tocNumber();
} }
else if ( arg3 instanceof CArray ) { else if ( arg3 instanceof cArray ) {
arg3 = arg3.getElement( 0 ).tocNumber(); arg3 = arg3.getElement( 0 ).tocNumber();
} }
arg3 = arg3.tocNumber(); arg3 = arg3.tocNumber();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof CError ) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
if ( arg2 instanceof CError ) if ( arg2 instanceof cError )
return this.value = arg2; return this.value = arg2;
if ( arg3 instanceof CError ) if ( arg3 instanceof cError )
return this.value = arg3; return this.value = arg3;
if ( arg3.getValue() < 0 ) { if ( arg3.getValue() < 0 ) {
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
var string = arg0.getValue(), old_string = arg1.getValue(), new_string = arg2.getValue(), index = 0, res; var string = arg0.getValue(), old_string = arg1.getValue(), new_string = arg2.getValue(), index = 0, res;
...@@ -1537,7 +1537,7 @@ cSUBSTITUTE.prototype.Calculate = function ( arg ) { ...@@ -1537,7 +1537,7 @@ cSUBSTITUTE.prototype.Calculate = function ( arg ) {
return equal; return equal;
} ) } )
return this.value = new CString( res ); return this.value = new cString( res );
} }
cSUBSTITUTE.prototype.getInfo = function () { cSUBSTITUTE.prototype.getInfo = function () {
...@@ -1568,22 +1568,22 @@ function cT() { ...@@ -1568,22 +1568,22 @@ function cT() {
cT.prototype = Object.create( cBaseFunction.prototype ) cT.prototype = Object.create( cBaseFunction.prototype )
cT.prototype.Calculate = function ( arg ) { cT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
else if ( arg0 instanceof CString || arg0 instanceof CError ) else if ( arg0 instanceof cString || arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg[0] instanceof CArray ) { else if ( arg[0] instanceof cArray ) {
arg0 = arg[0].getElementRowCol( 0, 0 ); arg0 = arg[0].getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof CString || arg0 instanceof CError ) if ( arg0 instanceof cString || arg0 instanceof cError )
return this.value = arg[0]; return this.value = arg[0];
else else
return this.value = new CEmpty(); return this.value = new cEmpty();
} }
cT.prototype.getInfo = function () { cT.prototype.getInfo = function () {
return { return {
...@@ -1613,37 +1613,37 @@ function cTEXT() { ...@@ -1613,37 +1613,37 @@ function cTEXT() {
cTEXT.prototype = Object.create( cBaseFunction.prototype ) cTEXT.prototype = Object.create( cBaseFunction.prototype )
cTEXT.prototype.Calculate = function ( arg ) { cTEXT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) { if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) { if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
} }
else if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) { else if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof CArray ) { else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof CError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
var _tmp = arg0.tocNumber(); var _tmp = arg0.tocNumber();
if ( _tmp instanceof CNumber ) if ( _tmp instanceof cNumber )
arg0 = _tmp; arg0 = _tmp;
var oFormat = oNumFormatCache.get( arg1.toString() ); var oFormat = oNumFormatCache.get( arg1.toString() );
var aText = oFormat.format( arg0.getValue(), arg0 instanceof CNumber ? CellValueType.Number : CellValueType.String, gc_nMaxDigCountView, null ); var aText = oFormat.format( arg0.getValue(), arg0 instanceof cNumber ? CellValueType.Number : CellValueType.String, gc_nMaxDigCountView, null );
var text = ""; var text = "";
for ( var i = 0, length = aText.length; i < length; ++i ) { for ( var i = 0, length = aText.length; i < length; ++i ) {
...@@ -1658,7 +1658,7 @@ cTEXT.prototype.Calculate = function ( arg ) { ...@@ -1658,7 +1658,7 @@ cTEXT.prototype.Calculate = function ( arg ) {
text += aText[i].text; text += aText[i].text;
} }
return this.value = new CString( text ); return this.value = new cString( text );
} }
cTEXT.prototype.getInfo = function () { cTEXT.prototype.getInfo = function () {
return { return {
...@@ -1689,19 +1689,19 @@ cTRIM.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1689,19 +1689,19 @@ cTRIM.prototype = Object.create( cBaseFunction.prototype )
cTRIM.prototype.Calculate = function ( arg ) { cTRIM.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
return this.value = new CString( arg0.getValue().replace( rx_space_g, function ( $0, $1, $2 ) { return this.value = new cString( arg0.getValue().replace( rx_space_g, function ( $0, $1, $2 ) {
var res; var res;
rx_space.test( $2[$1 + 1] ) ? res = "" : res = $2[$1]; rx_space.test( $2[$1 + 1] ) ? res = "" : res = $2[$1];
return res; return res;
...@@ -1735,16 +1735,16 @@ function cUPPER() { ...@@ -1735,16 +1735,16 @@ function cUPPER() {
cUPPER.prototype = Object.create( cBaseFunction.prototype ) cUPPER.prototype = Object.create( cBaseFunction.prototype )
cUPPER.prototype.Calculate = function ( arg ) { cUPPER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg0 instanceof CArray ) if ( arg0 instanceof cArray )
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
return this.value = new CString( arg0.getValue().toUpperCase() ); return this.value = new cString( arg0.getValue().toUpperCase() );
} }
cUPPER.prototype.getInfo = function () { cUPPER.prototype.getInfo = function () {
return { return {
...@@ -1776,24 +1776,24 @@ cVALUE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1776,24 +1776,24 @@ cVALUE.prototype = Object.create( cBaseFunction.prototype )
cVALUE.prototype.Calculate = function ( arg ) { cVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) { if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof CArray ) { else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof CError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
var res = g_oFormatParser.parse( arg0.getValue() ); var res = g_oFormatParser.parse( arg0.getValue() );
if ( res ) if ( res )
return this.value = new CNumber( res.value ); return this.value = new cNumber( res.value );
else else
return this.value = new CError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
cVALUE.prototype.getInfo = function () { cVALUE.prototype.getInfo = function () {
......
...@@ -3422,29 +3422,29 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){ ...@@ -3422,29 +3422,29 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){
var oNewElem; var oNewElem;
if(range.isOneCell()) if(range.isOneCell())
{ {
if(elem instanceof CRef3D) if(elem instanceof cRef3D)
oNewElem = new CRef3D(ref, elem.ws.getName(), elem._wb); oNewElem = new cRef3D(ref, elem.ws.getName(), elem._wb);
else if(elem instanceof CArea3D) else if(elem instanceof cArea3D)
{ {
var wsFrom = elem._wb.getWorksheetById( elem.wsFrom ).getName(); var wsFrom = elem._wb.getWorksheetById( elem.wsFrom ).getName();
var wsTo = elem._wb.getWorksheetById( elem.wsTo ).getName(); var wsTo = elem._wb.getWorksheetById( elem.wsTo ).getName();
oNewElem = new CArea3D(ref, wsFrom, wsTo, elem._wb); oNewElem = new cArea3D(ref, wsFrom, wsTo, elem._wb);
} }
else else
oNewElem = new CRef(ref, elem.ws); oNewElem = new cRef(ref, elem.ws);
} }
else else
{ {
if(elem instanceof CRef3D) if(elem instanceof cRef3D)
oNewElem = new CArea3D(ref, elem.ws.getName(), elem.ws.getName(), elem._wb); oNewElem = new cArea3D(ref, elem.ws.getName(), elem.ws.getName(), elem._wb);
else if(elem instanceof CArea3D) else if(elem instanceof cArea3D)
{ {
var wsFrom = elem._wb.getWorksheetById( elem.wsFrom ).getName(); var wsFrom = elem._wb.getWorksheetById( elem.wsFrom ).getName();
var wsTo = elem._wb.getWorksheetById( elem.wsTo ).getName(); var wsTo = elem._wb.getWorksheetById( elem.wsTo ).getName();
oNewElem = new CArea3D(ref, wsFrom, wsTo, elem._wb); oNewElem = new cArea3D(ref, wsFrom, wsTo, elem._wb);
} }
else else
oNewElem = new CArea(ref, elem.ws); oNewElem = new cArea(ref, elem.ws);
} }
if ( ref.indexOf( "$" ) > -1 ) if ( ref.indexOf( "$" ) > -1 )
oNewElem.isAbsolute = true; oNewElem.isAbsolute = true;
...@@ -3535,9 +3535,9 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){ ...@@ -3535,9 +3535,9 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
if ( c.formulaParsed && c.formulaParsed.outStack ) { if ( c.formulaParsed && c.formulaParsed.outStack ) {
for ( var i = 0, length = c.formulaParsed.outStack.length; i < length; i++ ) { for ( var i = 0, length = c.formulaParsed.outStack.length; i < length; i++ ) {
elem = c.formulaParsed.outStack[i]; elem = c.formulaParsed.outStack[i];
if ( elem instanceof CRef || elem instanceof CRef3D || elem instanceof CArea || elem instanceof CArea3D ) { if ( elem instanceof cRef || elem instanceof cRef3D || elem instanceof cArea || elem instanceof cArea3D ) {
var r = elem.getRange(); var r = elem.getRange();
if ( elem instanceof CArea3D && r.length > 0 ) if ( elem instanceof cArea3D && r.length > 0 )
r = r[0]; r = r[0];
if ( r && r.getNumFormatStr ) { if ( r && r.getNumFormatStr ) {
var sCurFormat = c.getNumFormatStr(); var sCurFormat = c.getNumFormatStr();
...@@ -3568,7 +3568,7 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){ ...@@ -3568,7 +3568,7 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
res = __cell.formulaParsed.calculate(); res = __cell.formulaParsed.calculate();
} }
else { else {
res = new CError( cErrorType.bad_reference ) res = new cError( cErrorType.bad_reference )
} }
if(res){ if(res){
if( res.type == cElementType.cell){ if( res.type == cElementType.cell){
......
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