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){
if( wb && !this.isArea ){
this.wb = wb;
var cell = this.wb.getWorksheetById(this.sheetId).getCell2(this.cellId);
if( cell )
this.cell = cell.getCells()[0];
else{
this.cell = null;
}
var c = new CellAddress(this.cellId);
this.cell = this.wb.getWorksheetById(this.sheetId)._getCellNoEmpty(c.getRow0(),c.getCol0());
}
//вершина которую мы прошли и поставили в очередь обхода
......@@ -1683,7 +1679,7 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
var se = a[i].getSlaveEdges();
if(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 ){
var _c = _ws.getCell2(cID).getCells()[0];
_c.setFormula(_c.formulaParsed.moveSheet(tempW).assemble());//Перестраиваем трехмерные ссылки в формуле.
......@@ -1891,7 +1887,8 @@ Workbook.prototype.recalc = function(is3D){
for(var i=0; i<this.getWorksheetCount();i++){
__ws = this.getWorksheet(i);
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 );
sr1 = recalcDependency.call(thas,dep1.badF,true);
sr2 = recalcDependency.call(thas,dep1.depF,false);
......@@ -3299,6 +3296,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
History.Create_NewPoint();
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.StartTransaction();
History.TurnOff();
var arrUndo={from:[],to:[]};
......@@ -3322,7 +3320,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
var _sn = n.getSlaveEdges2();
for( var _id in _sn ){
var cell = _sn[_id].returnCell();
if( undefined == cell ) { continue; }
if( undefined == cell || null == cell ) { continue; }
if( cell.formulaParsed ){
cell.formulaParsed.shiftCells( offset, oBBoxFrom, n, this.Id, false );
cell.setFormula(cell.formulaParsed.assemble());
......@@ -3408,17 +3406,18 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
if( _cell.hyperlinks.length > 0 ){
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 ) ){
savedHyperlinks.push( _cell.hyperlinks.splice(i,1)[0] );
this.getCell3(nRow,nCol).setHyperlink(_cell.hyperlinks.splice(i,1)[0],true)
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);
oTargetRow.c[nCol+offset.offsetCol] = _cell;
}
}
......@@ -3426,6 +3425,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
this.workbook.needRecalc = rec;
recalc(this.workbook);
// History.EndTransaction();
History.TurnOn();
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange,
this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0),
......@@ -3610,17 +3610,16 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){
/*
Построение графа зависимостей.
*/
var c;
var c, ca;
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 )
continue;
// if( !c.formulaParsed ){
if( c && c.sFormula ){
c.formulaParsed = new parserFormula( c.sFormula, c.oId.getID(), this );
// }
c.formulaParsed.parse();
c.formulaParsed.buildDependencies();
c.formulaParsed.parse();
c.formulaParsed.buildDependencies();
}
}
}
Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
......@@ -3639,17 +3638,13 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
if( g_oDefaultNum.f == c.getNumFormatStr() )
c.setNumFormat(thas.getCell(ca).getNumFormatStr());
}
if( cell.indexOf(":")>-1 ) return;
var __cell = this.getRange2(cell), res;
if( __cell )
__cell = __cell.getCells()[0];
else
return;
/*
Проверяем содержит ли ячейка формулу. Если нет, то выходим из функции.
*/
if ( !__cell.sFormula )
var celladd = this.getRange2(cell).getFirst(),
__cell = this._getCellNoEmpty( celladd.getRow0(),celladd.getCol0() ), res;
if( !__cell || !__cell.sFormula )
return;
/*
......@@ -3708,10 +3703,12 @@ Woorksheet.prototype._ReBuildFormulas=function(cellRange,lastSheetName,newSheetN
/*
Если существуют трехмерные ссылки на ячейки, то у них необходимо поменять имя листа на новое после переименования листа.
*/
var c, __ws = this;
var c, ca;
for(var i in cellRange){
c = this.getRange2(cellRange[i]).getCells()[0];
if( c.formulaParsed.is3D ){
ca = new CellAddress(i);
c = this._getCellNoEmpty(ca.getRow0(),ca.getCol0());
if( c && c.formulaParsed && c.formulaParsed.is3D ){
c.setFormula(c.formulaParsed.assemble());
}
}
......
......@@ -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.array] = _func[cElementType.cellsRange][cElementType.empty] = function(arg0,arg1,what,cellAddress){
var cross = arg0.cross(cellAddress);
if( cross ){
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)
return _func[cross.type][arg1.type](cross,arg1,what)
}
......@@ -561,40 +549,14 @@ _func[cElementType.number][cElementType.cellsRange] = _func[cElementType.string]
_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){
var cross = arg1.cross(cellAddress);
if( cross ){
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)
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);
if( cross1 && cross2 ){
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)
return _func[cross1.type][cross2.type](cross1,cross2,what)
}
......@@ -1220,7 +1182,7 @@ var cFormulaOperators = {
r.Calculate = function(arg){ //calculate operator
var arg0 = arg[0];
if( arg0 instanceof cArea){
arg0 = arg0.cross(arguments[1]);
arg0 = arg0.cross(arguments[1].first);
}
arg0 = arg0.tocNumber();
return this.value = arg0 instanceof cError ? arg0 : new cNumber( -arg0.getValue() )
......@@ -1239,7 +1201,7 @@ var cFormulaOperators = {
r.Calculate = function(arg){
var arg0 = arg[0];
if( arg0 instanceof cArea){
arg0 = arg0.cross(arguments[1]);
arg0 = arg0.cross(arguments[1].first);
}
arg0 = arg[0].tryConvert();
return this.value = arg0;
......@@ -3543,7 +3505,7 @@ var cFormulaFunction = {
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);
}
......@@ -3712,7 +3674,7 @@ var cFormulaFunction = {
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{
......@@ -3957,7 +3919,7 @@ var cFormulaFunction = {
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);
}
......@@ -7032,7 +6994,7 @@ var cFormulaFunction = {
return r;
},
'FINDB' : function(){
var r = new cBaseFunction();
var r = cFormulaFunction.TextAndData["FIND"]()
r.setName("FINDB");
return r;
},
......@@ -7049,20 +7011,84 @@ var cFormulaFunction = {
'LEFT' : function(){
var r = new cBaseFunction();
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;
},
'LEFTB' : function(){
var r = new cBaseFunction();
var r = cFormulaFunction.TextAndData["LEFT"]()
r.setName("LEFTB");
return r;
},
'LEN' : function(){
var r = new cBaseFunction();
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;
},
'LENB' : function(){
var r = new cBaseFunction();
var r = cFormulaFunction.TextAndData["LEN"]();
r.setName("LENB");
return r;
},
......@@ -7096,10 +7122,61 @@ var cFormulaFunction = {
'MID' : function(){
var r = new cBaseFunction();
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;
},
'MIDB' : function(){
var r = new cBaseFunction();
var r = cFormulaFunction.TextAndData["MID"]();
r.setName("MIDB");
return r;
},
......@@ -7243,10 +7320,49 @@ var cFormulaFunction = {
'RIGHT' : function(){
var r = new cBaseFunction();
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;
},
'RIGHTB' : function(){
var r = new cBaseFunction();
var r = cFormulaFunction.TextAndData["RIGHT"]()
r.setName("RIGHTB");
return r;
},
......@@ -7299,7 +7415,65 @@ var cFormulaFunction = {
},
'TEXT' : function(){
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.getInfo = function(){
return {
name:this.name,
args:"( value , format )"
};
}
return r;
},
'TRIM' : function(){
......@@ -7623,8 +7797,8 @@ function cRef(val,_ws){/*Ref means A1 for example*/
this.wb = _ws.workbook;
this.isAbsolute = false;
this.type = cElementType.cell;
this.range = _ws != undefined ? this.ws.getCell2(val) :this.wb.getWorksheet(this.wb.getActive()).getCell2(val);
this._valid = this.range ? true : false;
this.range = _ws.getRange2(val);
this._valid = new CellAddress(val).isValid();
}
extend(cRef,cBaseType);
cRef.prototype.getWsId = function(){ return this.ws.Id; }
......@@ -7632,8 +7806,7 @@ cRef.prototype.getValue = function(){
if( !this._valid ){
return new cError(cErrorType.bad_reference)
}
var c = this.range.getCells()[0];
switch (c.getType()){
switch (this.range.getType()){
case CellValueType.Number:{
var v = this.range.getValueWithoutFormat();
if( v == "" )
......@@ -7895,11 +8068,7 @@ cRef3D.prototype.isValid = function(){
else return false;
}
cRef3D.prototype.getValue = function(){
var _ws = this.ws ;
if( !_ws ){
return new cError( cErrorType.bad_reference );
}
var _r = _ws.getCell2(this._cells);
var _r = this.getRange();
if( !_r ){
return new cError( cErrorType.bad_reference );
}
......@@ -8554,7 +8723,7 @@ parserFormula.prototype = {
}
_tmp = currentElement.Calculate(arg,this.ws.getCell(this.cellAddress));
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 ){
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