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

добавлены функции: Left, LeftB, Right, RightB, Mid, MidB, Find, FindB, Len, LenB, Text;

убрано получение ячеек через функцию getCells; 
подправлено сохранение гиперлинком при перемещении рэйнжей.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47102 954022d7-b5bf-4e40-9824-e11837661b57
parent 2bd99211
...@@ -948,12 +948,8 @@ function Vertex(sheetId,cellId,wb){ ...@@ -948,12 +948,8 @@ function Vertex(sheetId,cellId,wb){
if( wb && !this.isArea ){ if( wb && !this.isArea ){
this.wb = wb; this.wb = wb;
var cell = this.wb.getWorksheetById(this.sheetId).getCell2(this.cellId); var c = new CellAddress(this.cellId);
if( cell ) this.cell = this.wb.getWorksheetById(this.sheetId)._getCellNoEmpty(c.getRow0(),c.getCol0());
this.cell = cell.getCells()[0];
else{
this.cell = null;
}
} }
//вершина которую мы прошли и поставили в очередь обхода //вершина которую мы прошли и поставили в очередь обхода
...@@ -1683,7 +1679,7 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){ ...@@ -1683,7 +1679,7 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
var se = a[i].getSlaveEdges(); var se = a[i].getSlaveEdges();
if(se){ if(se){
for(var id in se){ for(var id in se){
var _ws = this.getWorksheetById(se[id].sheetId), f = _ws.getCell2(se[id].cellId).getCells()[0].sFormula, cID = se[id].cellId; var cID = se[id].cellId, _ws = this.getWorksheetById(se[id].sheetId), f = _ws.getCell2(cID).getCells()[0].sFormula;
if( f.indexOf(tempW.wFN+":") > 0 || f.indexOf(":"+tempW.wFN) > 0 ){ if( f.indexOf(tempW.wFN+":") > 0 || f.indexOf(":"+tempW.wFN) > 0 ){
var _c = _ws.getCell2(cID).getCells()[0]; var _c = _ws.getCell2(cID).getCells()[0];
_c.setFormula(_c.formulaParsed.moveSheet(tempW).assemble());//Перестраиваем трехмерные ссылки в формуле. _c.setFormula(_c.formulaParsed.moveSheet(tempW).assemble());//Перестраиваем трехмерные ссылки в формуле.
...@@ -1891,7 +1887,8 @@ Workbook.prototype.recalc = function(is3D){ ...@@ -1891,7 +1887,8 @@ Workbook.prototype.recalc = function(is3D){
for(var i=0; i<this.getWorksheetCount();i++){ for(var i=0; i<this.getWorksheetCount();i++){
__ws = this.getWorksheet(i); __ws = this.getWorksheet(i);
for(var id in this.cwf[__ws.Id].cells){ for(var id in this.cwf[__ws.Id].cells){
if( __ws.getCell2(id).getCells()[0].formulaParsed.is3D ){ var c = new CellAddress(id);
if( __ws._getCellNoEmpty(c.getRow0(),c.getCol0()).formulaParsed.is3D ){
dep1 = this.dependencyFormulas.t_sort_slave( __ws.Id, id ); dep1 = this.dependencyFormulas.t_sort_slave( __ws.Id, id );
sr1 = recalcDependency.call(thas,dep1.badF,true); sr1 = recalcDependency.call(thas,dep1.badF,true);
sr2 = recalcDependency.call(thas,dep1.depF,false); sr2 = recalcDependency.call(thas,dep1.depF,false);
...@@ -3299,6 +3296,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3299,6 +3296,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
History.Create_NewPoint(); History.Create_NewPoint();
History.SetSelection(new Asc.Range(oBBoxFrom.c1, oBBoxFrom.r1, oBBoxFrom.c2, oBBoxFrom.r2)); History.SetSelection(new Asc.Range(oBBoxFrom.c1, oBBoxFrom.r1, oBBoxFrom.c2, oBBoxFrom.r2));
History.SetSelectionRedo(new Asc.Range(oBBoxTo.c1, oBBoxTo.r1, oBBoxTo.c2, oBBoxTo.r2)); History.SetSelectionRedo(new Asc.Range(oBBoxTo.c1, oBBoxTo.r1, oBBoxTo.c2, oBBoxTo.r2));
// History.StartTransaction();
History.TurnOff(); History.TurnOff();
var arrUndo={from:[],to:[]}; var arrUndo={from:[],to:[]};
...@@ -3322,7 +3320,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3322,7 +3320,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
var _sn = n.getSlaveEdges2(); var _sn = n.getSlaveEdges2();
for( var _id in _sn ){ for( var _id in _sn ){
var cell = _sn[_id].returnCell(); var cell = _sn[_id].returnCell();
if( undefined == cell ) { continue; } if( undefined == cell || null == cell ) { continue; }
if( cell.formulaParsed ){ if( cell.formulaParsed ){
cell.formulaParsed.shiftCells( offset, oBBoxFrom, n, this.Id, false ); cell.formulaParsed.shiftCells( offset, oBBoxFrom, n, this.Id, false );
cell.setFormula(cell.formulaParsed.assemble()); cell.setFormula(cell.formulaParsed.assemble());
...@@ -3408,12 +3406,13 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3408,12 +3406,13 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
if( _cell.hyperlinks.length > 0 ){ if( _cell.hyperlinks.length > 0 ){
for( var i = 0; i < _cell.hyperlinks.length; i++ ){ for( var i = 0; i < _cell.hyperlinks.length; i++ ){
if( !( oBBoxFrom.c1 <= _cell.hyperlinks[i].Ref.bbox.c1 && oBBoxFrom.r1 <= _cell.hyperlinks[i].Ref.bbox.r1 && oBBoxFrom.c2 >= _cell.hyperlinks[i].Ref.bbox.c2 && oBBoxFrom.r2 >= _cell.hyperlinks[i].Ref.bbox.r2 ) ){ if( !( oBBoxFrom.c1 <= _cell.hyperlinks[i].Ref.bbox.c1 && oBBoxFrom.r1 <= _cell.hyperlinks[i].Ref.bbox.r1 && oBBoxFrom.c2 >= _cell.hyperlinks[i].Ref.bbox.c2 && oBBoxFrom.r2 >= _cell.hyperlinks[i].Ref.bbox.r2 ) ){
savedHyperlinks.push( _cell.hyperlinks.splice(i,1)[0] ); this.getCell3(nRow,nCol).setHyperlink(_cell.hyperlinks.splice(i,1)[0],true)
i-=1; i-=1;
} }
else{
_cell.hyperlinks[i].Ref = this.getRange2(_cell.getName());
}
} }
if( savedHyperlinks.length > 0 )
this.getCell3(nRow,nCol).getCells()[0].hyperlinks = savedHyperlinks;
} }
var oTargetRow = this._getRow(nRow + offset.offsetRow); var oTargetRow = this._getRow(nRow + offset.offsetRow);
...@@ -3426,6 +3425,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3426,6 +3425,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
this.workbook.needRecalc = rec; this.workbook.needRecalc = rec;
recalc(this.workbook); recalc(this.workbook);
// History.EndTransaction();
History.TurnOn(); History.TurnOn();
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange, History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange,
this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0), this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0),
...@@ -3610,18 +3610,17 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){ ...@@ -3610,18 +3610,17 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){
/* /*
Построение графа зависимостей. Построение графа зависимостей.
*/ */
var c; var c, ca;
for(var i in cellRange){ for(var i in cellRange){
c = this.getRange2(cellRange[i]).getCells()[0]; ca = new CellAddress(i);
c = this._getCellNoEmpty(ca.getRow0(),ca.getCol0());
if( !c.sFormula ) if( c && c.sFormula ){
continue;
// if( !c.formulaParsed ){
c.formulaParsed = new parserFormula( c.sFormula, c.oId.getID(), this ); c.formulaParsed = new parserFormula( c.sFormula, c.oId.getID(), this );
// }
c.formulaParsed.parse(); c.formulaParsed.parse();
c.formulaParsed.buildDependencies(); c.formulaParsed.buildDependencies();
} }
}
} }
Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
var thas = this; var thas = this;
...@@ -3639,17 +3638,13 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){ ...@@ -3639,17 +3638,13 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
if( g_oDefaultNum.f == c.getNumFormatStr() ) if( g_oDefaultNum.f == c.getNumFormatStr() )
c.setNumFormat(thas.getCell(ca).getNumFormatStr()); c.setNumFormat(thas.getCell(ca).getNumFormatStr());
} }
if( cell.indexOf(":")>-1 ) return; if( cell.indexOf(":")>-1 ) return;
var __cell = this.getRange2(cell), res; var celladd = this.getRange2(cell).getFirst(),
if( __cell ) __cell = this._getCellNoEmpty( celladd.getRow0(),celladd.getCol0() ), res;
__cell = __cell.getCells()[0];
else if( !__cell || !__cell.sFormula )
return;
/*
Проверяем содержит ли ячейка формулу. Если нет, то выходим из функции.
*/
if ( !__cell.sFormula )
return; return;
/* /*
...@@ -3708,10 +3703,12 @@ Woorksheet.prototype._ReBuildFormulas=function(cellRange,lastSheetName,newSheetN ...@@ -3708,10 +3703,12 @@ Woorksheet.prototype._ReBuildFormulas=function(cellRange,lastSheetName,newSheetN
/* /*
Если существуют трехмерные ссылки на ячейки, то у них необходимо поменять имя листа на новое после переименования листа. Если существуют трехмерные ссылки на ячейки, то у них необходимо поменять имя листа на новое после переименования листа.
*/ */
var c, __ws = this; var c, ca;
for(var i in cellRange){ for(var i in cellRange){
c = this.getRange2(cellRange[i]).getCells()[0]; ca = new CellAddress(i);
if( c.formulaParsed.is3D ){ c = this._getCellNoEmpty(ca.getRow0(),ca.getCol0());
if( c && c.formulaParsed && c.formulaParsed.is3D ){
c.setFormula(c.formulaParsed.assemble()); c.setFormula(c.formulaParsed.assemble());
} }
} }
......
...@@ -541,19 +541,7 @@ _func[cElementType.cellsRange][cElementType.number] = _func[cElementType.cellsRa ...@@ -541,19 +541,7 @@ _func[cElementType.cellsRange][cElementType.number] = _func[cElementType.cellsRa
_func[cElementType.cellsRange][cElementType.bool] = _func[cElementType.cellsRange][cElementType.error] = _func[cElementType.cellsRange][cElementType.bool] = _func[cElementType.cellsRange][cElementType.error] =
_func[cElementType.cellsRange][cElementType.array] = _func[cElementType.cellsRange][cElementType.empty] = function(arg0,arg1,what,cellAddress){ _func[cElementType.cellsRange][cElementType.array] = _func[cElementType.cellsRange][cElementType.empty] = function(arg0,arg1,what,cellAddress){
var cross = arg0.cross(cellAddress); var cross = arg0.cross(cellAddress);
if( cross ){ return _func[cross.type][arg1.type](cross,arg1,what)
if( cross.r != undefined ){
arg0 = arg0.getValue2(new CellAddress(cross.r,arg0.getBBox().c1))
}
else if( cross.c != undefined ){
arg0 = arg0.getValue2(new CellAddress(arg0.getBBox().r1, cross.c))
}
else
return new cError( cErrorType.wrong_value_type );
}
else
return new cError( cErrorType.wrong_value_type );
return _func[arg0.type][arg1.type](arg0,arg1,what)
} }
...@@ -561,40 +549,14 @@ _func[cElementType.number][cElementType.cellsRange] = _func[cElementType.string] ...@@ -561,40 +549,14 @@ _func[cElementType.number][cElementType.cellsRange] = _func[cElementType.string]
_func[cElementType.bool][cElementType.cellsRange] = _func[cElementType.error][cElementType.cellsRange] = _func[cElementType.bool][cElementType.cellsRange] = _func[cElementType.error][cElementType.cellsRange] =
_func[cElementType.array][cElementType.cellsRange] = _func[cElementType.empty][cElementType.cellsRange] = function(arg0,arg1,what,cellAddress){ _func[cElementType.array][cElementType.cellsRange] = _func[cElementType.empty][cElementType.cellsRange] = function(arg0,arg1,what,cellAddress){
var cross = arg1.cross(cellAddress); var cross = arg1.cross(cellAddress);
if( cross ){ return _func[arg0.type][cross.type](arg0,cross,what)
if( cross.r != undefined ){
arg1 = arg1.getValue2(new CellAddress(cross.r,arg1.getBBox().c1))
}
else if( cross.c != undefined ){
arg1 = arg1.getValue2(new CellAddress(arg1.getBBox().r1, cross.c))
}
else
return new cError( cErrorType.wrong_value_type );
}
else
return new cError( cErrorType.wrong_value_type );
return _func[arg0.type][arg1.type](arg0,arg1,what)
} }
_func[cElementType.cellsRange][cElementType.cellsRange] = function(arg0,arg1,what,cellAddress){ _func[cElementType.cellsRange][cElementType.cellsRange] = function(arg0,arg1,what,cellAddress){
var cross1 = arg0.cross(cellAddress), var cross1 = arg0.cross(cellAddress),
cross2 = arg1.cross(cellAddress); cross2 = arg1.cross(cellAddress);
if( cross1 && cross2 ){ return _func[cross1.type][cross2.type](cross1,cross2,what)
if( cross1.r != undefined && cross2.r != undefined ){
arg0 = arg0.getValue2(new CellAddress(cross1.r,arg0.getBBox().c1))
arg1 = arg1.getValue2(new CellAddress(cross2.r,arg1.getBBox().c1))
}
else if( cross1.c != undefined && cross2.c != undefined ){
arg0 = arg0.getValue2(new CellAddress(arg0.getBBox().r1, cross1.c))
arg1 = arg1.getValue2(new CellAddress(arg1.getBBox().r1, cross2.c))
}
else
return new cError( cErrorType.wrong_value_type );
}
else
return new cError( cErrorType.wrong_value_type );
return _func[arg0.type][arg1.type](arg0,arg1,what)
} }
...@@ -1220,7 +1182,7 @@ var cFormulaOperators = { ...@@ -1220,7 +1182,7 @@ var cFormulaOperators = {
r.Calculate = function(arg){ //calculate operator r.Calculate = function(arg){ //calculate operator
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea){ if( arg0 instanceof cArea){
arg0 = arg0.cross(arguments[1]); arg0 = arg0.cross(arguments[1].first);
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
return this.value = arg0 instanceof cError ? arg0 : new cNumber( -arg0.getValue() ) return this.value = arg0 instanceof cError ? arg0 : new cNumber( -arg0.getValue() )
...@@ -1239,7 +1201,7 @@ var cFormulaOperators = { ...@@ -1239,7 +1201,7 @@ var cFormulaOperators = {
r.Calculate = function(arg){ r.Calculate = function(arg){
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea){ if( arg0 instanceof cArea){
arg0 = arg0.cross(arguments[1]); arg0 = arg0.cross(arguments[1].first);
} }
arg0 = arg[0].tryConvert(); arg0 = arg[0].tryConvert();
return this.value = arg0; return this.value = arg0;
...@@ -3543,7 +3505,7 @@ var cFormulaFunction = { ...@@ -3543,7 +3505,7 @@ var cFormulaFunction = {
var c = new CellAddress(bb.r1+numberRow,resC,0); var c = new CellAddress(bb.r1+numberRow,resC,0);
var v = arg1.getWS().getRange(c,c).getCells()[0].getValueWithoutFormat(); var v = arg1.getWS()._getCellNoEmpty(c.getRow0(),c.getCol0()).getValueWithoutFormat();
return this.value = checkTypeCell(v); return this.value = checkTypeCell(v);
} }
...@@ -3712,7 +3674,7 @@ var cFormulaFunction = { ...@@ -3712,7 +3674,7 @@ var cFormulaFunction = {
var c = new CellAddress(BBox.r1+resR,BBox.c1+resC) var c = new CellAddress(BBox.r1+resR,BBox.c1+resC)
return this.value = checkTypeCell( _arg2.getWS().getRange(c,c).getCells()[0].getValueWithoutFormat() ); return this.value = checkTypeCell( _arg2.getWS()._getCellNoEmpty(c.getRow0(),c.getCol0()).getValueWithoutFormat() );
} }
else{ else{
...@@ -3957,7 +3919,7 @@ var cFormulaFunction = { ...@@ -3957,7 +3919,7 @@ var cFormulaFunction = {
var c = new CellAddress(resR,bb.c1+numberCol,0); var c = new CellAddress(resR,bb.c1+numberCol,0);
var v = arg1.getWS().getRange(c,c).getCells()[0].getValueWithoutFormat(); var v = arg1.getWS()._getCellNoEmpty(c.getRow0(),c.getCol0()).getValueWithoutFormat();
return this.value = checkTypeCell(v); return this.value = checkTypeCell(v);
} }
...@@ -7032,7 +6994,7 @@ var cFormulaFunction = { ...@@ -7032,7 +6994,7 @@ var cFormulaFunction = {
return r; return r;
}, },
'FINDB' : function(){ 'FINDB' : function(){
var r = new cBaseFunction(); var r = cFormulaFunction.TextAndData["FIND"]()
r.setName("FINDB"); r.setName("FINDB");
return r; return r;
}, },
...@@ -7049,20 +7011,84 @@ var cFormulaFunction = { ...@@ -7049,20 +7011,84 @@ var cFormulaFunction = {
'LEFT' : function(){ 'LEFT' : function(){
var r = new cBaseFunction(); var r = new cBaseFunction();
r.setName("LEFT"); r.setName("LEFT");
r.setArgumentsMin(1);
r.setArgumentsMax(2);
r.Calculate = function(arg){
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber(1) : arg[1];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
}
arg0 = arg0.tocString();
arg1 = arg1.tocNumber();
if( arg0 instanceof cArray && arg1 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
arg1 = arg1.getElementRowCol(0,0);
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
}
else if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
}
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
if( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new cString( arg0.getValue().substring(0, arg1.getValue()) )
}
r.getInfo = function(){
return {
name:this.name,
args:"( string [ , number-chars ] )"
};
}
return r; return r;
}, },
'LEFTB' : function(){ 'LEFTB' : function(){
var r = new cBaseFunction(); var r = cFormulaFunction.TextAndData["LEFT"]()
r.setName("LEFTB"); r.setName("LEFTB");
return r; return r;
}, },
'LEN' : function(){ 'LEN' : function(){
var r = new cBaseFunction(); var r = new cBaseFunction();
r.setName("LEN"); r.setName("LEN");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}
arg0 = arg0.tocString();
if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
}
if ( arg0 instanceof cError ) return this.value = arg0;
return this.value = new cNumber( arg0.getValue().length )
}
r.getInfo = function(){
return {
name:this.name,
args:"( string )"
};
}
return r; return r;
}, },
'LENB' : function(){ 'LENB' : function(){
var r = new cBaseFunction(); var r = cFormulaFunction.TextAndData["LEN"]();
r.setName("LENB"); r.setName("LENB");
return r; return r;
}, },
...@@ -7096,10 +7122,61 @@ var cFormulaFunction = { ...@@ -7096,10 +7122,61 @@ var cFormulaFunction = {
'MID' : function(){ 'MID' : function(){
var r = new cBaseFunction(); var r = new cBaseFunction();
r.setName("MID"); r.setName("MID");
r.setArgumentsMin(3);
r.setArgumentsMax(3);
r.Calculate = function(arg){
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
}
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){
arg2 = arg2.cross(arguments[1].first);
}
arg0 = arg0.tocString();
arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber();
if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
}
if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
}
if( arg2 instanceof cArray ){
arg2 = arg2.getElementRowCol(0,0);
}
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2;
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 );
var l = arg0.getValue().length;
if( arg1.getValue() > l )
return this.value = new cString("");
/* if( arg1.getValue() < l )
return this.value = arg0; */
return this.value = new cString( arg0.getValue().substr( arg1.getValue() == 0 ? 0 : arg1.getValue()-1, arg2.getValue() ) )
}
r.getInfo = function(){
return {
name:this.name,
args:"( string , start-pos , number-chars )"
};
}
return r; return r;
}, },
'MIDB' : function(){ 'MIDB' : function(){
var r = new cBaseFunction(); var r = cFormulaFunction.TextAndData["MID"]();
r.setName("MIDB"); r.setName("MIDB");
return r; return r;
}, },
...@@ -7243,10 +7320,49 @@ var cFormulaFunction = { ...@@ -7243,10 +7320,49 @@ var cFormulaFunction = {
'RIGHT' : function(){ 'RIGHT' : function(){
var r = new cBaseFunction(); var r = new cBaseFunction();
r.setName("RIGHT"); r.setName("RIGHT");
r.setArgumentsMin(1);
r.setArgumentsMax(2);
r.Calculate = function(arg){
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber(1) : arg[1];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
}
arg0 = arg0.tocString();
arg1 = arg1.tocNumber();
if( arg0 instanceof cArray && arg1 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
arg1 = arg1.getElementRowCol(0,0);
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
}
else if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
}
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
if( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
var l = arg0.getValue().length, _number = l-arg1.getValue();
return this.value = new cString( arg0.getValue().substring( _number < 0 ? 0 : _number , l) )
}
r.getInfo = function(){
return {
name:this.name,
args:"( string [ , number-chars ] )"
};
}
return r; return r;
}, },
'RIGHTB' : function(){ 'RIGHTB' : function(){
var r = new cBaseFunction(); var r = cFormulaFunction.TextAndData["RIGHT"]()
r.setName("RIGHTB"); r.setName("RIGHTB");
return r; return r;
}, },
...@@ -7299,7 +7415,65 @@ var cFormulaFunction = { ...@@ -7299,7 +7415,65 @@ var cFormulaFunction = {
}, },
'TEXT' : function(){ 'TEXT' : function(){
var r = new cBaseFunction(); var r = new cBaseFunction();
r.setArgumentsMin(2);
r.setArgumentsMax(2);
r.Calculate = function(arg){
var arg0 = arg[0], arg1 = arg[1];
if( arg0 instanceof cRef || arg0 instanceof cRef3D){
arg0 = arg0.getValue();
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
}
if( arg1 instanceof cRef || arg1 instanceof cRef3D){
arg1 = arg1.getValue();
}
else if ( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
}
else if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
}
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
arg0 = arg0.tocString();
var _tmp = arg0.tocNumber();
if( _tmp instanceof cNumber )
arg0 = _tmp;
var oFormat = oNumFormatCache.get(arg1.toString());
var aText = oFormat.format(arg0.getValue(), arg0 instanceof cNumber ? CellValueType.Number : CellValueType.String, gc_nMaxDigCountView, null);
var text = "";
for(var i = 0, length = aText.length; i < length; ++i)
{
if(aText[i].format && aText[i].format.skip ){
text += " ";
continue;
}
if(aText[i].format && aText[i].format.repeat )
continue;
text += aText[i].text;
}
return this.value = new cString(text);
}
r.setName("TEXT"); r.setName("TEXT");
r.getInfo = function(){
return {
name:this.name,
args:"( value , format )"
};
}
return r; return r;
}, },
'TRIM' : function(){ 'TRIM' : function(){
...@@ -7623,8 +7797,8 @@ function cRef(val,_ws){/*Ref means A1 for example*/ ...@@ -7623,8 +7797,8 @@ function cRef(val,_ws){/*Ref means A1 for example*/
this.wb = _ws.workbook; this.wb = _ws.workbook;
this.isAbsolute = false; this.isAbsolute = false;
this.type = cElementType.cell; this.type = cElementType.cell;
this.range = _ws != undefined ? this.ws.getCell2(val) :this.wb.getWorksheet(this.wb.getActive()).getCell2(val); this.range = _ws.getRange2(val);
this._valid = this.range ? true : false; this._valid = new CellAddress(val).isValid();
} }
extend(cRef,cBaseType); extend(cRef,cBaseType);
cRef.prototype.getWsId = function(){ return this.ws.Id; } cRef.prototype.getWsId = function(){ return this.ws.Id; }
...@@ -7632,8 +7806,7 @@ cRef.prototype.getValue = function(){ ...@@ -7632,8 +7806,7 @@ cRef.prototype.getValue = function(){
if( !this._valid ){ if( !this._valid ){
return new cError(cErrorType.bad_reference) return new cError(cErrorType.bad_reference)
} }
var c = this.range.getCells()[0]; switch (this.range.getType()){
switch (c.getType()){
case CellValueType.Number:{ case CellValueType.Number:{
var v = this.range.getValueWithoutFormat(); var v = this.range.getValueWithoutFormat();
if( v == "" ) if( v == "" )
...@@ -7895,11 +8068,7 @@ cRef3D.prototype.isValid = function(){ ...@@ -7895,11 +8068,7 @@ cRef3D.prototype.isValid = function(){
else return false; else return false;
} }
cRef3D.prototype.getValue = function(){ cRef3D.prototype.getValue = function(){
var _ws = this.ws ; var _r = this.getRange();
if( !_ws ){
return new cError( cErrorType.bad_reference );
}
var _r = _ws.getCell2(this._cells);
if( !_r ){ if( !_r ){
return new cError( cErrorType.bad_reference ); return new cError( cErrorType.bad_reference );
} }
...@@ -8554,7 +8723,7 @@ parserFormula.prototype = { ...@@ -8554,7 +8723,7 @@ parserFormula.prototype = {
} }
_tmp = currentElement.Calculate(arg,this.ws.getCell(this.cellAddress)); _tmp = currentElement.Calculate(arg,this.ws.getCell(this.cellAddress));
if( _tmp.numFormat !== undefined && _tmp.numFormat !== null ){ if( _tmp.numFormat !== undefined && _tmp.numFormat !== null ){
numFormat = _tmp.numFormat //> numFormat ? _tmp.numFormat : numFormat; numFormat = _tmp.numFormat; //> numFormat ? _tmp.numFormat : numFormat;
} }
else if( numFormat < 0 ){ else if( numFormat < 0 ){
numFormat = currentElement.numFormat; numFormat = currentElement.numFormat;
......
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