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

добавлена NPV.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47362 954022d7-b5bf-4e40-9824-e11837661b57
parent 89185771
......@@ -68,34 +68,34 @@ _func[cElementType.empty] = [];
_func[cElementType.array] = [];
_func[cElementType.number][cElementType.number] = function(arg0,arg1,what){
switch (what){
_func[cElementType.number][cElementType.number] = function (arg0, arg1, what) {
switch (what) {
case ">":
return new cBool( arg0.getValue() > arg1.getValue() );
return new cBool(arg0.getValue() > arg1.getValue());
case ">=":
return new cBool( arg0.getValue() >= arg1.getValue() );
return new cBool(arg0.getValue() >= arg1.getValue());
case "<":
return new cBool( arg0.getValue() < arg1.getValue() );
return new cBool(arg0.getValue() < arg1.getValue());
case "<=":
return new cBool( arg0.getValue() <= arg1.getValue() );
return new cBool(arg0.getValue() <= arg1.getValue());
case "=":
return new cBool( arg0.getValue() == arg1.getValue() );
return new cBool(arg0.getValue() == arg1.getValue());
case "<>":
return new cBool( arg0.getValue() != arg1.getValue() );
return new cBool(arg0.getValue() != arg1.getValue());
case "-":
return new cNumber( arg0.getValue() - arg1.getValue() );
return new cNumber(arg0.getValue() - arg1.getValue());
case "+":
return new cNumber( arg0.getValue() + arg1.getValue() );
return new cNumber(arg0.getValue() + arg1.getValue());
case "/":
if (arg1.getValue() != 0)
return new cNumber( arg0.getValue() / arg1.getValue() );
return new cNumber(arg0.getValue() / arg1.getValue());
else
return new cError( cErrorType.division_by_zero );
return new cError(cErrorType.division_by_zero);
case "*":
return new cNumber( arg0.getValue() * arg1.getValue() );
return new cNumber(arg0.getValue() * arg1.getValue());
}
return new cError( cErrorType.wrong_value_type);
}
return new cError(cErrorType.wrong_value_type);
};
_func[cElementType.number][cElementType.string] = function(arg0,arg1,what){
switch (what){
......@@ -116,7 +116,7 @@ _func[cElementType.number][cElementType.string] = function(arg0,arg1,what){
return new cError( cErrorType.wrong_value_type );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.number][cElementType.bool] = function(arg0,arg1,what){
switch (what){
......@@ -151,11 +151,11 @@ _func[cElementType.number][cElementType.bool] = function(arg0,arg1,what){
return new cNumber( arg0.getValue() * _arg.getValue() );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.number][cElementType.error] = function(arg0,arg1,what){
return arg1;
}
};
_func[cElementType.number][cElementType.empty] = function(arg0,arg1,what){
switch (what){
......@@ -181,7 +181,7 @@ _func[cElementType.number][cElementType.empty] = function(arg0,arg1,what){
return new cNumber( 0 );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.string][cElementType.number] = function(arg0,arg1,what){
......@@ -202,7 +202,7 @@ _func[cElementType.string][cElementType.number] = function(arg0,arg1,what){
return new cError( cErrorType.wrong_value_type );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.string][cElementType.string] = function(arg0,arg1,what){
switch (what){
......@@ -246,7 +246,7 @@ _func[cElementType.string][cElementType.string] = function(arg0,arg1,what){
return new cNumber( _arg0.getValue() * _arg1.getValue() );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.string][cElementType.bool] = function(arg0,arg1,what){
switch (what){
......@@ -288,11 +288,11 @@ _func[cElementType.string][cElementType.bool] = function(arg0,arg1,what){
return new cNumber( _arg0.getValue() * _arg1.getValue() );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.string][cElementType.error] = function(arg0,arg1,what){
return arg1;
}
};
_func[cElementType.string][cElementType.empty] = function(arg0,arg1,what){
switch (what){
......@@ -315,7 +315,7 @@ _func[cElementType.string][cElementType.empty] = function(arg0,arg1,what){
return new cError( cErrorType.wrong_value_type );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.bool][cElementType.number] = function(arg0,arg1,what){
......@@ -351,7 +351,7 @@ _func[cElementType.bool][cElementType.number] = function(arg0,arg1,what){
return new cNumber( _arg.getValue() * arg1.getValue() );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.bool][cElementType.string] = function(arg0,arg1,what){
switch (what){
......@@ -389,7 +389,7 @@ _func[cElementType.bool][cElementType.string] = function(arg0,arg1,what){
return new cNumber( _arg0.getValue() * _arg1.getValue() );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.bool][cElementType.bool] = function(arg0,arg1,what){
switch (what){
......@@ -425,11 +425,11 @@ _func[cElementType.bool][cElementType.bool] = function(arg0,arg1,what){
return new cNumber( _arg0.getValue() * _arg1.getValue() );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.bool][cElementType.error] = function(arg0,arg1,what){
return arg1;
}
};
_func[cElementType.bool][cElementType.empty] = function(arg0,arg1,what){
switch (what){
......@@ -455,14 +455,14 @@ _func[cElementType.bool][cElementType.empty] = function(arg0,arg1,what){
return new cNumber( 0 );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.error][cElementType.number] = _func[cElementType.error][cElementType.string] =
_func[cElementType.error][cElementType.bool] = _func[cElementType.error][cElementType.error] =
_func[cElementType.error][cElementType.empty] = function(arg0,arg1,what){
return arg0;
}
};
_func[cElementType.empty][cElementType.number] = function(arg0,arg1,what){
......@@ -491,7 +491,7 @@ _func[cElementType.empty][cElementType.number] = function(arg0,arg1,what){
return new cNumber( 0 );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.empty][cElementType.string] = function(arg0,arg1,what){
switch (what){
......@@ -514,7 +514,7 @@ _func[cElementType.empty][cElementType.string] = function(arg0,arg1,what){
return new cError( cErrorType.wrong_value_type );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.empty][cElementType.bool] = function(arg0,arg1,what){
switch (what){
......@@ -542,11 +542,11 @@ _func[cElementType.empty][cElementType.bool] = function(arg0,arg1,what){
return new cNumber( 0 );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.empty][cElementType.error] = function(arg0,arg1,what){
return arg1;
}
};
_func[cElementType.empty][cElementType.empty] = function(arg0,arg1,what){
switch (what){
......@@ -567,7 +567,7 @@ _func[cElementType.empty][cElementType.empty] = function(arg0,arg1,what){
return new cNumber( 0 );
}
return new cError( cErrorType.wrong_value_type);
}
};
_func[cElementType.cellsRange][cElementType.number] = _func[cElementType.cellsRange][cElementType.string] =
......@@ -575,7 +575,7 @@ _func[cElementType.cellsRange][cElementType.bool] = _func[cElementType.cellsRang
_func[cElementType.cellsRange][cElementType.array] = _func[cElementType.cellsRange][cElementType.empty] = function(arg0,arg1,what,cellAddress){
var cross = arg0.cross(cellAddress);
return _func[cross.type][arg1.type](cross,arg1,what)
}
};
_func[cElementType.number][cElementType.cellsRange] = _func[cElementType.string][cElementType.cellsRange] =
......@@ -583,14 +583,14 @@ _func[cElementType.bool][cElementType.cellsRange] = _func[cElementType.error][cE
_func[cElementType.array][cElementType.cellsRange] = _func[cElementType.empty][cElementType.cellsRange] = function(arg0,arg1,what,cellAddress){
var cross = arg1.cross(cellAddress);
return _func[arg0.type][cross.type](arg0,cross,what)
}
};
_func[cElementType.cellsRange][cElementType.cellsRange] = function(arg0,arg1,what,cellAddress){
var cross1 = arg0.cross(cellAddress),
cross2 = arg1.cross(cellAddress);
return _func[cross1.type][cross2.type](cross1,cross2,what)
}
};
_func[cElementType.array][cElementType.number] = _func[cElementType.array][cElementType.string] =
......@@ -602,7 +602,7 @@ _func[cElementType.array][cElementType.empty] = function(arg0,arg1,what,cellAddr
res.addElement( _func[elem.type][arg1.type](elem,arg1,what) );
})
return res;
}
};
_func[cElementType.number][cElementType.array] = _func[cElementType.string][cElementType.array] =
......@@ -612,9 +612,9 @@ _func[cElementType.empty][cElementType.array] = function(arg0,arg1,what,cellAddr
arg1.foreach(function(elem,r,c){
if( !res.array[r] ) res.addRow();
res.addElement( _func[arg0.type][elem.type](arg0,elem,what) );
})
});
return res;
}
};
_func.binarySearch = function(sElem, arrTagert, regExp){
......@@ -666,7 +666,7 @@ _func.binarySearch = function(sElem, arrTagert, regExp){
return last-1;/* Искомый элемент не найден. Но если вам вдруг надо его вставить со сдвигом, то его место - last. */
}
}
};
/*Functions that checks of an element in formula*/
var rx_operators = new RegExp("^ *[-+*/^&%<=>:]"),
......@@ -2725,6 +2725,72 @@ var cFormulaFunction = {
'NPV' : function(){
var r = new cBaseFunction();
r.setName("NPV");
r.setArgumentsMin(2);
r.setArgumentsMax(255);
r.Calculate = function(arg){
var arg0 = arg[0], arg1 = arg[1], iStart = 1, res = 0, rate;
function elemCalc(rate,value,step){
return value / Math.pow(1+rate,step);
}
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
}
arg0 = arg0.tocNumber();
if ( arg0 instanceof cError )
return this.value = arg0;
rate = arg0.getValue();
if( rate == -1)
return this.value = new cError( cErrorType.division_by_zero );
for(var i = 1; i < this.getArguments(); i++){
var argI = arg[i];
if( argI instanceof cArea || argI instanceof cArea3D ){
var argIArr = argI.getValue();
for (var j = 0; j < argIArr.length; j++){
if( argIArr[j] instanceof cNumber ){
res += elemCalc( rate, argIArr[j].getValue(), iStart++ );
}
}
continue;
}
else if( argI instanceof cArray ){
argI.foreach(function(elem,r,c){
if( elem instanceof cNumber ){
res += elemCalc( rate, elem.getValue(), iStart++ );
}
})
continue;
}
argI = argI.tocNumber();
if( argI instanceof cError )
continue;
res += elemCalc( rate, argI.getValue(), iStart++ );
}
return this.value = new cNumber(res);
};
r.getInfo = function(){
return {
name:this.name,
args:"( rate , argument-list )"
};
};
r.setFormat(r.formatType.noneFormat);
return r;
},
'ODDFPRICE' : function(){
......@@ -8574,11 +8640,11 @@ var cFormulaFunction = {
arg0 = arg0.getElementRowCol(0,0);
}
arg0 = arg0.tocString();
if ( arg0 instanceof cError )
return this.value = arg0;
arg0 = arg0.tocString();
var res = g_oFormatParser.parse(arg0.getValue());
if( res )
......@@ -8624,10 +8690,10 @@ function cNumber(val){
this.value = parseFloat(val);
}
extend(cNumber,cBaseType);
cNumber.prototype.getValue = function(){ return this.value.toFixed(cExcelSignificantDigits)-0; }
cNumber.prototype.tocString = function(){ return new cString( ""+this.value ); }
cNumber.prototype.tocNumber = function(){ return this; }
cNumber.prototype.tocBool = function(){ return new cBool( this.value != 0 ); }
cNumber.prototype.getValue = function(){ return this.value.toFixed(cExcelSignificantDigits)-0; };
cNumber.prototype.tocString = function(){ return new cString( ""+this.value ); };
cNumber.prototype.tocNumber = function(){ return this; };
cNumber.prototype.tocBool = function(){ return new cBool( this.value != 0 ); };
/** @constructor */
function cString(val){
......@@ -8649,7 +8715,7 @@ cString.prototype.tocNumber = function(){
if ( !isNaN(_numberValue) )
return new cNumber(_numberValue);
}
}
};
cString.prototype.tocBool = function(){
if ( parserHelp.isBoolean(this.value, 0) ){
if( parserHelp.operand_str == "TRUE" )
......@@ -8659,8 +8725,8 @@ cString.prototype.tocBool = function(){
}
else
return this;
}
cString.prototype.tocString = function(){ return this; }
};
cString.prototype.tocString = function(){ return this; };
/** @constructor */
function cBool(val){
......@@ -8677,12 +8743,12 @@ function cBool(val){
}
}
extend(cBool,cBaseType);
cBool.prototype.toString = function(){ return this.value.toString().toUpperCase(); }
cBool.prototype.getValue = function(){ return this.toString(); }
cBool.prototype.tocNumber = function(){ return new cNumber( this.value ? 1.0: 0.0 ); }
cBool.prototype.tocString = function(){ return new cString( this.value ? "TRUE": "FALSE" ); }
cBool.prototype.tocBool = function(){ return this; }
cBool.prototype.toBool = function(){ return this.value; }
cBool.prototype.toString = function(){ return this.value.toString().toUpperCase(); };
cBool.prototype.getValue = function(){ return this.toString(); };
cBool.prototype.tocNumber = function(){ return new cNumber( this.value ? 1.0: 0.0 ); };
cBool.prototype.tocString = function(){ return new cString( this.value ? "TRUE": "FALSE" ); };
cBool.prototype.tocBool = function(){ return this; };
cBool.prototype.toBool = function(){ return this.value; };
/** @constructor */
function cError(val){
......@@ -8762,7 +8828,7 @@ function cError(val){
}
}
extend(cError,cBaseType);
cError.prototype.tocNumber = cError.prototype.tocString = cError.prototype.tocBool = cError.prototype.tocEmpty = function(){ return this; }
cError.prototype.tocNumber = cError.prototype.tocString = cError.prototype.tocBool = cError.prototype.tocEmpty = function(){ return this; };
/** @constructor */
function cArea(val,_ws){/*Area means "A1:E5" for example*/
......@@ -8776,7 +8842,7 @@ function cArea(val,_ws){/*Area means "A1:E5" for example*/
// this._valid = this.range ? true : false;
}
extend(cArea,cBaseType);
cArea.prototype.getWsId = function(){ return this.ws.Id; }
cArea.prototype.getWsId = function(){ return this.ws.Id; };
cArea.prototype.getValue = function(){
var _val = [], r = this.getRange();
if( !r ){
......@@ -8806,7 +8872,7 @@ cArea.prototype.getValue = function(){
}
});
return _val;
}
};
cArea.prototype.getValue2 = function(cell){
var _val = [], r = this.getRange();
if( !r ){
......@@ -8837,19 +8903,19 @@ cArea.prototype.getValue2 = function(cell){
}
});
return _val[0];
}
cArea.prototype.getRange = function(){ return this.ws.getRange2(this._cells); }
cArea.prototype.tocNumber = function(){ return this.getValue()[0].tocNumber(); }
cArea.prototype.tocString = function(){ return this.getValue()[0].tocString(); }
cArea.prototype.tocBool = function(){ return this.getValue()[0].tocBool(); }
cArea.prototype.toString = function(){ return this._cells; }
};
cArea.prototype.getRange = function(){ return this.ws.getRange2(this._cells); };
cArea.prototype.tocNumber = function(){ return this.getValue()[0].tocNumber(); };
cArea.prototype.tocString = function(){ return this.getValue()[0].tocString(); };
cArea.prototype.tocBool = function(){ return this.getValue()[0].tocBool(); };
cArea.prototype.toString = function(){ return this._cells; };
cArea.prototype.setRange = function(cell){
this._cells = this.value = cell;
this.range = this.ws.getRange2(cell);
this._valid = this.range ? true : false;
}
cArea.prototype.getWS = function(){ return this.ws; }
cArea.prototype.getBBox = function(){ return this.getRange().getBBox(); }
};
cArea.prototype.getWS = function(){ return this.ws; };
cArea.prototype.getBBox = function(){ return this.getRange().getBBox(); };
cArea.prototype.cross = function(arg){
var r = this.getRange();
if( !r )
......@@ -8867,13 +8933,13 @@ cArea.prototype.cross = function(arg){
}
else
return new cError( cErrorType.wrong_value_type );
}
};
cArea.prototype.isValid = function(){
var r = this.getRange();
if(!r)
return false;
return true;
}
};
cArea.prototype.countCells = function(){
var r = this.getRange(), bbox = r.bbox,
count = (Math.abs(bbox.c1 - bbox.c2) + 1)*(Math.abs(bbox.r1 - bbox.r2) + 1);
......@@ -8881,7 +8947,7 @@ cArea.prototype.countCells = function(){
count--;
})
return new cNumber( count );
}
};
/** @constructor */
function cRef(val,_ws){/*Ref means A1 for example*/
......@@ -8895,7 +8961,7 @@ function cRef(val,_ws){/*Ref means A1 for example*/
this._valid = new CellAddress(val.replace(/\$/g,"")).isValid();
}
extend(cRef,cBaseType);
cRef.prototype.getWsId = function(){ return this.ws.Id; }
cRef.prototype.getWsId = function(){ return this.ws.Id; };
cRef.prototype.getValue = function(){
if( !this._valid ){
return new cError(cErrorType.bad_reference)
......@@ -8926,17 +8992,17 @@ cRef.prototype.getValue = function(){
return new cError(parserHelp.operand_str)
else return new cString(_val);
}
}
cRef.prototype.tocNumber = function(){ return this.getValue().tocNumber(); }
cRef.prototype.tocString = function(){ return new cString(""+this.range.getValueWithFormat()); }
cRef.prototype.tocBool = function(){ return this.getValue().tocBool(); }
cRef.prototype.tryConvert = function(){ return this.getValue(); }
cRef.prototype.toString = function(){ return this._cells; }
cRef.prototype.getRange = function(){ return this.range; }
cRef.prototype.getWS = function(){ return this.ws; }
};
cRef.prototype.tocNumber = function(){ return this.getValue().tocNumber(); };
cRef.prototype.tocString = function(){ return new cString(""+this.range.getValueWithFormat()); };
cRef.prototype.tocBool = function(){ return this.getValue().tocBool(); };
cRef.prototype.tryConvert = function(){ return this.getValue(); };
cRef.prototype.toString = function(){ return this._cells; };
cRef.prototype.getRange = function(){ return this.range; };
cRef.prototype.getWS = function(){ return this.ws; };
cRef.prototype.isValid = function(){
return this._valid;
}
};
/** @constructor */
function cArea3D(val,_wsFrom, _wsTo,wb){/*Area3D means "Sheat1!A1:E5" for example*/
......@@ -8969,7 +9035,7 @@ cArea3D.prototype.range = function(wsRange){
}
return r;
};
cArea3D.prototype.getRange = function(){ return this.range(this.wsRange()); }
cArea3D.prototype.getRange = function(){ return this.range(this.wsRange()); };
cArea3D.prototype.getValue = function(){
var _wsA = this.wsRange();
var _val = [];
......@@ -9014,7 +9080,7 @@ cArea3D.prototype.getValue = function(){
})
}
return _val;
}
};
cArea3D.prototype.getValue2 = function(cell){
var _wsA = this.wsRange();
var _val = [];
......@@ -9058,7 +9124,7 @@ cArea3D.prototype.getValue2 = function(cell){
}
})
return _val[0];
}
};
cArea3D.prototype.changeSheet = function(lastName,newName){
if( this.wsFrom == this._wb.getWorksheetByName(lastName).getId() && this.wsTo == this._wb.getWorksheetByName(lastName).getId() ){
this.wsFrom = this.wsTo = this._wb.getWorksheetByName(newName).getId();
......@@ -9069,7 +9135,7 @@ cArea3D.prototype.changeSheet = function(lastName,newName){
else if( this.wsTo == this._wb.getWorksheetByName(lastName).getId() ){
this.wsTo = this._wb.getWorksheetByName(newName).getId();
}
}
};
cArea3D.prototype.moveSheet = function(tempW){
if( this.wsFrom == this.wsTo ){
return;
......@@ -9088,7 +9154,7 @@ cArea3D.prototype.moveSheet = function(tempW){
this.wsTo = this._wb.getWorksheet(tempW.wFI).getId();
}
}
}
};
cArea3D.prototype.toString = function(){
var wsFrom = this._wb.getWorksheetById( this.wsFrom ).getName();
var wsTo = this._wb.getWorksheetById( this.wsTo ).getName();
......@@ -9104,11 +9170,11 @@ cArea3D.prototype.toString = function(){
wsFrom+":"+wsTo :
wsFrom)
+"!"+this._cells;
}
cArea3D.prototype.tocNumber = function(){ return this.getValue()[0].tocNumber(); }
cArea3D.prototype.tocString = function(){ return this.getValue()[0].tocString(); }
cArea3D.prototype.tocBool = function(){ return this.getValue()[0].tocBool(); }
cArea3D.prototype.getWS = function(){ return this.wsRange()[0]; }
};
cArea3D.prototype.tocNumber = function(){ return this.getValue()[0].tocNumber(); };
cArea3D.prototype.tocString = function(){ return this.getValue()[0].tocString(); };
cArea3D.prototype.tocBool = function(){ return this.getValue()[0].tocBool(); };
cArea3D.prototype.getWS = function(){ return this.wsRange()[0]; };
cArea3D.prototype.cross = function(arg){
if( this.wsFrom != this.wsTo )
return new cError( cErrorType.wrong_value_type );
......@@ -9128,8 +9194,8 @@ cArea3D.prototype.cross = function(arg){
}
else
return new cError( cErrorType.wrong_value_type );
}
cArea3D.prototype.getBBox = function(){ return this.getRange()[0].getBBox(); }
};
cArea3D.prototype.getBBox = function(){ return this.getRange()[0].getBBox(); };
cArea3D.prototype.isValid = function(){
var r = this.getRange();
for( var i=0;i<r.length;i++){
......@@ -9137,7 +9203,7 @@ cArea3D.prototype.isValid = function(){
return false;
}
return true;
}
};
cArea3D.prototype.countCells = function(){
var _wsA = this.wsRange();
var _val = [];
......@@ -9166,7 +9232,7 @@ cArea3D.prototype.countCells = function(){
})
}
return new cNumber( count );
}
};
/** @constructor */
function cRef3D(val,_wsFrom,wb){/*Ref means Sheat1!A1 for example*/
......@@ -9178,18 +9244,18 @@ function cRef3D(val,_wsFrom,wb){/*Ref means Sheat1!A1 for example*/
this.ws = this._wb.getWorksheetByName( _wsFrom );
}
extend(cRef3D,cBaseType);
cRef3D.prototype.getWsId = function(){ return this.ws.Id; }
cRef3D.prototype.getWsId = function(){ return this.ws.Id; };
cRef3D.prototype.getRange = function(){
if(this.ws)
return this.ws.getRange2(this._cells);
else
return null;
}
};
cRef3D.prototype.isValid = function(){
if( this.getRange() )
return true;
else return false;
}
};
cRef3D.prototype.getValue = function(){
var _r = this.getRange();
if( !_r ){
......@@ -9221,16 +9287,16 @@ cRef3D.prototype.getValue = function(){
return new cError(parserHelp.operand_str)
else return new cString(_val);
}
}
cRef3D.prototype.tocBool = function(){ return this.getValue().tocBool(); }
cRef3D.prototype.tocNumber = function(){ return this.getValue().tocNumber(); }
cRef3D.prototype.tocString = function(){ return this.getValue().tocString(); }
cRef3D.prototype.tryConvert = function(){ return this.getValue(); }
};
cRef3D.prototype.tocBool = function(){ return this.getValue().tocBool(); };
cRef3D.prototype.tocNumber = function(){ return this.getValue().tocNumber(); };
cRef3D.prototype.tocString = function(){ return this.getValue().tocString(); };
cRef3D.prototype.tryConvert = function(){ return this.getValue(); };
cRef3D.prototype.changeSheet = function(lastName,newName){
if( this.ws.getName() == lastName ){
this.ws = this._wb.getWorksheetByName( newName );
}
}
};
cRef3D.prototype.toString = function(){
var wsName = this.ws.getName();
if( !rx_test_ws_name.test(wsName) ){
......@@ -9239,8 +9305,8 @@ cRef3D.prototype.toString = function(){
else{
return wsName+"!"+this._cells;
}
}
cRef3D.prototype.getWS = function(){ return this.ws; }
};
cRef3D.prototype.getWS = function(){ return this.ws; };
/** @constructor */
function cEmpty(){
......@@ -9248,10 +9314,10 @@ function cEmpty(){
this.type = cElementType.empty;
}
extend(cEmpty,cBaseType);
cEmpty.prototype.tocNumber = function(){ return new cNumber(0); }
cEmpty.prototype.tocBool = function(){ return new cBool(false); }
cEmpty.prototype.tocString = function(){ return new cString(""); }
cEmpty.prototype.toString = function(){ return ""; }
cEmpty.prototype.tocNumber = function(){ return new cNumber(0); };
cEmpty.prototype.tocBool = function(){ return new cBool(false); };
cEmpty.prototype.tocString = function(){ return new cString(""); };
cEmpty.prototype.toString = function(){ return ""; };
/** @constructor */
function cName(val,wb){
......@@ -9268,16 +9334,14 @@ cName.prototype.toRef = function(wsID){
_wsFrom = _3DRefTmp[1];
_wsTo = ( (_3DRefTmp[2] !== null) && (_3DRefTmp[2] !== undefined) )? _3DRefTmp[2] : _wsFrom;
if ( parserHelp.isArea(ref,ref.indexOf("!")+1) ){
var r = new cArea3D(parserHelp.operand_str,_wsFrom, _wsTo, this.wb);
return r;
return new cArea3D(parserHelp.operand_str,_wsFrom, _wsTo, this.wb);
}
else if ( parserHelp.isRef(ref,ref.indexOf("!")+1) ){
var r = new cRef3D(parserHelp.operand_str,_wsFrom,this.wb);
return r;
return new cRef3D(parserHelp.operand_str,_wsFrom,this.wb);
}
}
return new cError("#REF!");
}
};
/** @constructor */
function cArray(){
......@@ -9292,7 +9356,7 @@ extend(cArray,cBaseType);
cArray.prototype.addRow = function(){
this.array[this.array.length] = [];
this.countElementInRow[this.rowCount++] = 0;
}
};
cArray.prototype.addElement = function(element){
if( this.array.length == 0){
this.addRow();
......@@ -9302,24 +9366,24 @@ cArray.prototype.addElement = function(element){
subArr[subArr.length] = element;
this.countElementInRow[this.rowCount-1]++;
this.countElement++;
}
};
cArray.prototype.getRow = function(rowIndex){
if( rowIndex < 0 || rowIndex > this.array.length-1 )
return null;
return this.array[rowIndex];
}
};
cArray.prototype.getCol = function(colIndex){
var col = [];
for( var i = 0; i < this.rowCount; i++){
col.push(this.array[i][colIndex])
}
return col;
}
};
cArray.prototype.getElementRowCol = function(row,col){
if( row > this.rowCount || col > this.getCountElementInRow() )
return new cError( cErrorType.not_available );
return this.array[row][col];
}
};
cArray.prototype.getElement = function(index){
for( var i = 0; i < this.rowCount; i++){
if( index > this.countElementInRow[i].length )
......@@ -9328,7 +9392,7 @@ cArray.prototype.getElement = function(index){
return this.array[i][index];
}
return null;
}
};
cArray.prototype.foreach = function(action){
if( typeof (action) != 'function' ){ return; }
for( var ir = 0; ir < this.rowCount; ir++ ){
......@@ -9337,10 +9401,12 @@ cArray.prototype.foreach = function(action){
return true;
}
}
}
cArray.prototype.getCountElement = function(){ return this.countElement; }
cArray.prototype.getCountElementInRow = function(){ return this.countElementInRow[0]; }
cArray.prototype.getRowCount = function(){ return this.rowCount; }
};
cArray.prototype.getCountElement = function(){ return this.countElement; };
cArray.prototype.getCountElementInRow = function(){ return this.countElementInRow[0]; };
cArray.prototype.getRowCount = function () {
return this.rowCount;
};
cArray.prototype.tocNumber = function(){
var retArr = new cArray();
for( var ir = 0; ir < this.rowCount; ir++,retArr.addRow()){
......@@ -9351,7 +9417,7 @@ cArray.prototype.tocNumber = function(){
break;
}
return retArr;
}
};
cArray.prototype.tocString = function(){
var retArr = new cArray();
for( var ir = 0; ir < this.rowCount; ir++,retArr.addRow()){
......@@ -9362,7 +9428,7 @@ cArray.prototype.tocString = function(){
break;
}
return retArr;
}
};
cArray.prototype.tocBool = function(){
var retArr = new cArray();
for( var ir = 0; ir < this.rowCount; ir++,retArr.addRow()){
......@@ -9373,7 +9439,7 @@ cArray.prototype.tocBool = function(){
break;
}
return retArr;
}
};
cArray.prototype.toString = function(){
var ret="";
for( var ir = 0; ir < this.rowCount; ir++,ret+=";" ){
......@@ -9388,9 +9454,9 @@ cArray.prototype.toString = function(){
ret = ret.substring(0,ret.length-1)
}
if ( ret[ret.length-1]==";")
ret = ret.substring(0,ret.length-1)
ret = ret.substring(0, ret.length - 1);
return "{"+ret+"}";
}
};
cArray.prototype.isValidArray = function(){
for( var i = 0; i < this.rowCount-1; i++){
if( this.countElementInRow[i] - this.countElementInRow[i+1] == 0)
......@@ -9399,7 +9465,7 @@ cArray.prototype.isValidArray = function(){
return false;
}
return true;
}
};
/** класс отвечающий за парсинг строки с формулой, подсчета формулы, перестройки формулы при манипуляции с ячейкой*/
/** @constructor */
......@@ -10109,8 +10175,7 @@ parserFormula.prototype = {
r = ref.getRange();
r.setOffset({offsetCol:0, offsetRow:offset.offsetRow});
ref.value = ref._cells = "$"+r.first.getID();
}
else{
} else{
r = ref.getRange();
r.setOffset({offsetCol:offset.offsetCol, offsetRow:0});
ref.value = ref._cells = r.first.getColLetter()+"$"+r.first.getRow();
......
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