Commit 7f4be356 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov

Добавлены функции в формулах:

ACCRINT, ACCRINTM, AMORDEGRC, AMORLINC, CUMIPMT, EDDECT, IRR, ISPMT, XIRR, XNPV, INDEX, MATCH, OFFSET, TRANSPOSE, STDEVP, STDEVPA, STDEYX, VARA, VARP, VARPA.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55076 954022d7-b5bf-4e40-9824-e11837661b57
parent 9bc3fc7c
This diff is collapsed.
This diff is collapsed.
......@@ -7,28 +7,44 @@
* Time: 13:24
* To change this template use File | Settings | File Templates.
*/
function GetDiffDate360( nDay1, nMonth1, nYear1, bLeapYear1, nDay2, nMonth2, nYear2, bUSAMethod ) {
if ( nDay1 == 31 )
nDay1--;
else if ( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 && !bLeapYear1 ) ) ) )
nDay1 = 30;
if ( nDay2 == 31 ) {
if ( bUSAMethod && nDay1 != 30 ) {
nDay2 = 1;
if ( nMonth2 == 12 ) {
nYear2++;
nMonth2 = 1;
function yearFrac(d1, d2, mode) {
var date1 = d1.getDate(),
month1 = d1.getMonth(),
year1 = d1.getFullYear(),
date2 = d2.getDate(),
month2 = d2.getMonth(),
year2 = d2.getFullYear();
switch ( mode ) {
case 0:
return new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, d2.isLeapYear(), date2, month2, year2, false ) ) / 360 );
case 1:
var yc = Math.abs( year2 - year1 ),
sd = year1 > year2 ? d2 : d1,
yearAverage = sd.isLeapYear() ? 366 : 365, dayDiff = Math.abs( d2 - d1 );
for ( var i = 0; i < yc; i++ ) {
sd.addYears( 1 );
yearAverage += sd.isLeapYear() ? 366 : 365;
}
else
nMonth2++;
}
else
nDay2 = 30;
yearAverage /= (yc + 1);
dayDiff /= (yearAverage * c_msPerDay);
return new cNumber( dayDiff );
case 2:
var dayDiff = Math.abs( d2 - d1 );
dayDiff /= (360 * c_msPerDay);
return new cNumber( dayDiff );
case 3:
var dayDiff = Math.abs( d2 - d1 );
dayDiff /= (365 * c_msPerDay);
return new cNumber( dayDiff );
case 4:
return new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, d2.isLeapYear(), date2, month2, year2, true ) ) / 360 );
default:
return new cError( cErrorType.not_numeric );
}
return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - nYear1 * 360;
}
cFormulaFunction.DateAndTime = {
'groupName':"DateAndTime",
'DATE':cDATE,
......@@ -1681,39 +1697,8 @@ cYEARFRAC.prototype.Calculate = function ( arg ) {
val0 = Date.prototype.getDateFromExcel( val0 );
val1 = Date.prototype.getDateFromExcel( val1 );
var date1 = val0.getDate(), date2 = val1.getDate(), month1 = val0.getMonth(), month2 = val1.getMonth(), year1 = val0.getFullYear(), year2 = val1.getFullYear();
switch ( arg2.getValue() ) {
case 0:
return this.value = new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, val1.isLeapYear(), date2, month2, year2, false ) ) / 360 );
break;
case 1:
var yc = Math.abs( year2 - year1 ),
sd = year1 > year2 ? val1 : val0,
yearAverage = sd.isLeapYear() ? 366 : 365, dayDiff = Math.abs( val1 - val0 );
for ( var i = 0; i < yc; i++ ) {
sd.addYears( 1 );
yearAverage += sd.isLeapYear() ? 366 : 365;
}
yearAverage /= (yc + 1);
dayDiff /= (yearAverage * c_msPerDay);
return this.value = new cNumber( dayDiff );
break;
case 2:
var dayDiff = Math.abs( val1 - val0 );
dayDiff /= (360 * c_msPerDay);
return this.value = new cNumber( dayDiff );
break;
case 3:
var dayDiff = Math.abs( val1 - val0 );
dayDiff /= (365 * c_msPerDay);
return this.value = new cNumber( dayDiff );
break;
case 4:
return this.value = new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, val1.isLeapYear(), date2, month2, year2, true ) ) / 360 );
break;
default:
return this.value = new cError( cErrorType.not_numeric )
}
return this.value = yearFrac( val0, val1, arg2.getValue() );
}
cYEARFRAC.prototype.getInfo = function () {
......@@ -1721,4 +1706,4 @@ cYEARFRAC.prototype.getInfo = function () {
name:this.name,
args:"( start-date , end-date [ , basis ] )"
};
}
}
\ No newline at end of file
......@@ -446,9 +446,71 @@ function cHYPERLINK() {
cHYPERLINK.prototype = Object.create( cBaseFunction.prototype )
function cINDEX() {
cBaseFunction.call( this, "INDEX" );
// cBaseFunction.call( this, "INDEX" );
this.name = "INDEX";
this.type = cElementType.func;
this.value = null;
this.argumentsMin = 2;
this.argumentsCurrent = 0;
this.argumentsMax = 4;
this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat:-2
};
this.numFormat = this.formatType.def;
}
cINDEX.prototype = Object.create( cBaseFunction.prototype )
cINDEX.prototype.Calculate = function ( arg ) {
var arg0 = arg[0],
arg1 = arg[1] && !(arg[1] instanceof cEmpty) ? arg[1] : 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),
isArrayForm = false, res;
if( arg0 instanceof cArea3D ){
return this.value = new cError( cErrorType.not_available );
}
else if( arg0 instanceof cError ){
return this.value = arg0;
}
arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber();
arg3 = arg3.tocNumber();
if( arg1 instanceof cError || arg2 instanceof cError || arg3 instanceof cError ){
return this.value = new cError( cErrorType.wrong_value_type );
}
if( arg1.getValue() < 0 || arg2.getValue() < 0 ){
return this.value = new cError( cErrorType.wrong_value_type );
}
if( arg0 instanceof cArray ){
arg0 = arg0.getMatrix();
}
else if( arg0 instanceof cArea ){
arg0 = arg0.getMatrix();
}
else{
arg0 = [[arg0.tryConvert()]]
}
res = arg0[arg1.getValue()-1];
if( res )
res = res[arg2.getValue()-1];
return this.value = res ? res : new cError( cErrorType.bad_reference );
}
cINDEX.prototype.getInfo = function () {
return {
name:this.name,
args:"( array , [ row-number ] [ , [ column-number ] ] ) "+this.name+"( reference , [ row-number ] [ , [ column-number ] [ , [ area-number ] ] ] )"
};
}
function cINDIRECT() {
// cBaseFunction.call( this, "INDIRECT" );
......@@ -549,7 +611,6 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
return this.value = found_operand;
}
return this.value = new cError( cErrorType.bad_reference );
}
......@@ -710,14 +771,160 @@ cLOOKUP.prototype.getInfo = function () {
}
function cMATCH() {
cBaseFunction.call( this, "MATCH" );
// cBaseFunction.call( this, "MATCH" );
this.name = "MATCH";
this.type = cElementType.func;
this.value = null;
this.argumentsMin = 2;
this.argumentsCurrent = 0;
this.argumentsMax = 3;
this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat:-2
};
this.numFormat = this.formatType.def;
}
cMATCH.prototype = Object.create( cBaseFunction.prototype )
cMATCH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber(1);
function findMatch(a0,a1,a2){
var a1RowCount = a1.length, a1ColumnCount = a1[0].length,
a0Value = a0.getValue(), a2Value = a2.getValue(),
arr = [], res = new cError( cErrorType.not_available ),
index = -1;
if( a1RowCount > 1 && a1ColumnCount > 1 ){
return new cError( cErrorType.not_available );
}
else if( a1RowCount == 1 && a1ColumnCount > 1 ){
for(var i = 0; i < a1ColumnCount; i++){
arr[i] = a1[0][i].getValue();
}
}
else if( a1RowCount > 1 && a1ColumnCount == 1 ){
for(var i = 0; i < a1RowCount; i++){
arr[i] = a1[i][0].getValue();
}
}
else {
arr[0]=a1[0][0];
}
if( !(a2Value == 1 || a2Value == 0 || a2Value == -1) ){
return new cError( cErrorType.not_numeric );
}
if( a2Value == -1 ){
for(var i = 0; i<arr.length; i++){
if( arr[i] >= a0Value ){
index = i;
}
else
break;
}
}
else if( a2Value == 0 ){
if( a0 instanceof cString ){
for(var i = 0; i<arr.length; i++){
if( searchRegExp2(arr[i].toString(),a0Value) ){
index = i;
}
}
}
else{
for(var i = 0; i<arr.length; i++){
if( arr[i] == a0Value ){
index = i;
}
}
}
}
else if( a2Value == 1 ){
for(var i = 0; i<arr.length; i++){
if( arr[i] <= a0Value ){
index = i;
}
else
break;
}
}
if( index > -1 )
res = new cNumber(index+1);
return res;
}
if( arg0 instanceof cArea3D || arg0 instanceof cArray || arg0 instanceof cArea ){
return this.value = new cError( cErrorType.not_available );
}
else if( arg0 instanceof cError ){
return this.value = arg0;
}
/* else{
}*/
if( !(arg1 instanceof cArray || arg1 instanceof cArea) ){
return this.value = new cError( cErrorType.not_available );
}
else {
arg1 = arg1.getMatrix();
}
if( arg2 instanceof cNumber || arg2 instanceof cBool ){
}
else if( arg2 instanceof cError ){
return this.value = arg2;
}
else{
return this.value = new cError( cErrorType.not_available );
}
return this.value = findMatch(arg0,arg1,arg2)
}
cMATCH.prototype.getInfo = function () {
return {
name:this.name,
args:"( lookup-value , lookup-array [ , [ match-type ]] )"
};
}
function cOFFSET() {
cBaseFunction.call( this, "OFFSET" );
// cBaseFunction.call( this, "OFFSET" );
this.name = "OFFSET";
this.type = cElementType.func;
this.value = null;
this.argumentsMin = 3;
this.argumentsCurrent = 0;
this.argumentsMax = 5;
this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat:-2
};
this.numFormat = this.formatType.def;
}
cOFFSET.prototype = Object.create( cBaseFunction.prototype )
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);
if(1){}
}
cOFFSET.prototype.getInfo = function () {
return {
name:this.name,
args:"( reference , rows , cols [ , [ height ] [ , [ width ] ] ] )"
};
}
function cROW() {
// cBaseFunction.call( this, "ROW" );
......@@ -822,9 +1029,62 @@ function cRTD() {
cRTD.prototype = Object.create( cBaseFunction.prototype )
function cTRANSPOSE() {
cBaseFunction.call( this, "TRANSPOSE" );
// cBaseFunction.call( this, "TRANSPOSE" );
this.name = "TRANSPOSE";
this.type = cElementType.func;
this.value = null;
this.argumentsMin = 1;
this.argumentsCurrent = 0;
this.argumentsMax = 1;
this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat:-2
};
this.numFormat = this.formatType.noneFormat;
}
cTRANSPOSE.prototype = Object.create( cBaseFunction.prototype )
cTRANSPOSE.prototype.Calculate = function ( arg ) {
function TransposeMatrix( A ) {
var tMatrix = [], res = new cArray();
for ( var i = 0; i < A.length; i++ ) {
for ( var j = 0; j < A[i].length; j++ ) {
if(!tMatrix[j]) tMatrix[j] = [];
tMatrix[j][i] = A[i][j];
}
}
res.fillFromArray( tMatrix );
return res;
}
var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArray ) {
arg0 = arg0.getMatrix();
}
else if( arg0 instanceof cNumber || arg0 instanceof cString || arg0 instanceof cBool || arg0 instanceof cRef || arg0 instanceof cRef3D ){
return this.value = arg0.getValue();
}
else if( arg0 instanceof cError ){
return this.value = arg0;
}
else
return this.value = new cError( cErrorType.not_available );
return this.value = TransposeMatrix( arg0 );
}
cTRANSPOSE.prototype.getInfo = function () {
return {
name:this.name,
args:"( array )"
};
}
function VHLOOKUPCache(bHor){
this.cacheId = {};
......
......@@ -4041,6 +4041,69 @@ function parseNum( str ) {
return !isNaN( str );
}
function matching( x, y, oper ) {
var res = false, rS;
if ( y instanceof cString ) {
rS = searchRegExp2( x.value, y.toString() )
switch ( oper ) {
case "<>":
res = !rS;
break;
case "=":
default:
res = rS;
break;
}
}
else if ( typeof x === typeof y ) {
switch ( oper ) {
case "<>":
res = (x.value != y.value);
break;
case ">":
res = (x.value > y.value);
break;
case "<":
res = (x.value < y.value);
break;
case ">=":
res = (x.value >= y.value);
break;
case "<=":
res = (x.value <= y.value);
break;
case "=":
default:
res = (x.value == y.value);
break;
}
}
return res;
}
function GetDiffDate360( nDay1, nMonth1, nYear1, bLeapYear1, nDay2, nMonth2, nYear2, bUSAMethod ) {
if ( nDay1 == 31 )
nDay1--;
else if ( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 && !bLeapYear1 ) ) ) )
nDay1 = 30;
if ( nDay2 == 31 ) {
if ( bUSAMethod && nDay1 != 30 ) {
nDay2 = 1;
if ( nMonth2 == 12 ) {
nYear2++;
nMonth2 = 1;
}
else
nMonth2++;
}
else
nDay2 = 30;
}
return ( nDay2 - nDay1 ) + ( nMonth2 - nMonth1 ) * 30 + ( nYear2 - nYear1 ) * 360;
}
function searchRegExp( str, flags ) {
var vFS = str
.replace( /(\\)/g, "\\" )
......
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