Commit d6c6035a authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Добавил функции:

get3DRef - Возвращает ссылку на диапазон с листом (название листа экранируется)
getEscapeSheetName - Возвращает экранируемое название листа
Переделал код на эти функции

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56802 954022d7-b5bf-4e40-9824-e11837661b57
parent 42d58a57
This diff is collapsed.
......@@ -579,24 +579,15 @@ CChartSpace.prototype =
changeListName: function(val, oldName, newName)
{
var _new_name;
if(!rx_test_ws_name.test(newName))
{
_new_name = "'" + newName + "'";
}
else
{
_new_name = newName;
}
if(val)
{
if(val.numRef && typeof val.numRef.f === "string")
{
val.numRef.setF(val.numRef.f.replace(new RegExp(oldName,'g'), _new_name));
val.numRef.setF(val.numRef.f.replace(new RegExp(oldName,'g'), newName));
}
if(val.strRef && typeof val.strRef.f === "string")
{
val.strRef.setF(val.strRef.f.replace(new RegExp(oldName,'g'), _new_name));
val.strRef.setF(val.strRef.f.replace(new RegExp(oldName,'g'), newName));
}
}
},
......@@ -1527,16 +1518,9 @@ CChartSpace.prototype =
var startCell = new CellAddress(r1, c1, 0);
var endCell = new CellAddress(r2, c2, 0);
if (startCell && endCell && this.bbox.worksheet)
{
var wsName = this.bbox.worksheet.sName;
if ( !rx_test_ws_name.test(wsName) )
wsName = "'" + wsName + "'";
if (startCell.getID() == endCell.getID())
ret.range = wsName + "!" + startCell.getID();
else
ret.range = wsName + "!" + startCell.getID() + ":" + endCell.getID();
if (startCell && endCell && this.bbox.worksheet) {
ret.range = parserHelp.get3DRef(this.bbox.worksheet.sName, startCell.getID() === endCell.getID() ?
startCell.getID() : startCell.getID() + ':' + endCell.getID());
}
}
return ret;
......
......@@ -15,6 +15,9 @@ function fSortDescending( a, b ) {
return b - a;
}
/**
* @constructor
*/
function test_ws_name() {
var self = new XRegExp( "[^\\p{L}(\\p{L}\\d._)*]" );
self.regexp_letter = new XRegExp( "^\\p{L}[\\p{L}\\d.]*$" );
......@@ -244,7 +247,10 @@ var rx_operators = /^ *[-+*\/^&%<=>:] */,
rg_complex_number = new XRegExp( "^(?<real>[-+]?(?:\\d*(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?))?(?<img>([-+]?(\\d*(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?)?[ij])?)", "g" )
//вспомогательный объект для парсинга формул и проверки строки по регуляркам указанным выше.
/**
* вспомогательный объект для парсинга формул и проверки строки по регуляркам указанным выше.
* @constructor
*/
function parserHelper() {
}
parserHelper.prototype = {
......@@ -258,12 +264,12 @@ parserHelper.prototype = {
this._reset();
}
var str = formula.substring( start_pos )
var str = formula.substring( start_pos );
var match = str.match( rx_operators );
if ( match == null || match == undefined )
return false;
else {
var mt = str.match( rx_LG )
var mt = str.match( rx_LG );
if ( mt ) match = mt;
this.operand_str = match[0].replace( rx_space_g, "" );
this.pCurrPos += match[0].length;
......@@ -568,6 +574,17 @@ parserHelper.prototype = {
}
// Возвращаем ошибку
return null;
}
},
// Возвращает ссылку на диапазон с листом (название листа экранируется)
get3DRef: function (sheet, range) {
var result = rx_test_ws_name.test(sheet) ? sheet : "'" + sheet.replace(/'/g, "''") + "'";
return result + '!' + range;
},
// Возвращает экранируемое название листа
getEscapeSheetName: function (sheet) {
return rx_test_ws_name.test(sheet) ? sheet : "'" + sheet.replace(/'/g, "''") + "'";
}
};
var parserHelp = new parserHelper();
\ No newline at end of file
......@@ -126,31 +126,21 @@ cADDRESS.prototype.Calculate = function ( arg ) {
break;
}
if ( sheetName instanceof cEmpty ) {
return this.value = new cString( strRef );
}
else {
if ( !rx_test_ws_name.test( sheetName.toString() ) ) {
return this.value = new cString( "'" + sheetName.toString().replace( /'/g, "''" ) + "'" + "!" + strRef );
}
else {
return this.value = new cString( sheetName.toString() + "!" + strRef );
}
}
}
return this.value = new cString((sheetName instanceof cEmpty) ? strRef :
parserHelp.get3DRef(sheetName.toString(), strRef));
};
cADDRESS.prototype.getInfo = function () {
return {
name:this.name,
args:"( row-number , col-number [ , [ ref-type ] [ , [ A1-ref-style-flag ] [ , sheet-name ] ] ] )"
};
}
};
function cAREAS() {
cBaseFunction.call( this, "AREAS" );
}
cAREAS.prototype = Object.create( cBaseFunction.prototype )
cAREAS.prototype = Object.create( cBaseFunction.prototype );
function cCHOOSE() {
// cBaseFunction.call( this, "CHOOSE" );
......
......@@ -907,14 +907,8 @@ cArea3D.prototype.toString = function () {
wsTo = this._wb.getWorksheetById( this.wsTo ).getName(),
name = Asc.g_oRangeCache.getActiveRange(this._cells);
name = name && name.getName ? name.getName() : this._cells;
if ( rx_test_ws_name.test( wsFrom ) && rx_test_ws_name.test( wsTo ) ) {
return (wsFrom !== wsTo ? wsFrom + ":" + wsTo : wsFrom) + "!" + name;
}
else{
wsFrom = wsFrom.replace( /'/g, "''" );
wsTo = wsTo.replace( /'/g, "''" );
return "'" + (wsFrom !== wsTo ? wsFrom + ":" + wsTo : wsFrom) + "'!" + name;
}
return parserHelp.get3DRef(wsFrom !== wsTo ? wsFrom + ':' + wsTo : wsFrom, name);
};
cArea3D.prototype.tocNumber = function () {
return this.getValue()[0].tocNumber();
......@@ -1260,13 +1254,7 @@ cRef3D.prototype.changeSheet = function ( lastName, newName ) {
}
};
cRef3D.prototype.toString = function () {
var wsName = this.ws.getName();
if ( rx_test_ws_name.test( wsName ) ) {
return wsName + "!" + this._cells;
}
else {
return "'" + wsName.replace( /'/g, "''" ) + "'" + "!" + this._cells;
}
return parserHelp.get3DRef(this.ws.getName(), this._cells);
};
cRef3D.prototype.getWS = function () {
return this.ws;
......
......@@ -2040,7 +2040,7 @@ Woorksheet.prototype.setName=function(name){
if(name.length <= g_nSheetNameMaxLength)
{
var lastName = this.sName;
this.sName = name;
this.sName = name;
History.Create_NewPoint();
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_Rename, this.getId(), null, new UndoRedoData_FromTo(lastName, name));
......@@ -2049,8 +2049,8 @@ Woorksheet.prototype.setName=function(name){
this.workbook.getWorksheetById(id)._ReBuildFormulas(this.workbook.cwf[id].cells,lastName,this.sName);
}
var _lastName = !rx_test_ws_name.test(lastName) ? "'" + lastName + "'" : lastName;
var _newName = !rx_test_ws_name.test(this.sName) ? "'" + this.sName + "'" : this.sName;
var _lastName = parserHelp.getEscapeSheetName(lastName);
var _newName = parserHelp.getEscapeSheetName(this.sName);
for (var key in this.workbook.aWorksheets)
{
......@@ -7945,13 +7945,9 @@ NameGenerator.prototype = {
this.addName(oDefinedName.Name);
},
addTableName : function(sName, ws, Ref){
var sDefinedNameRef = ws.getName();
if(false == rx_test_ws_name.test(sDefinedNameRef))
sDefinedNameRef = "'" + sDefinedNameRef + "'";
sDefinedNameRef += "!" + Ref;
var oNewDefinedName = new DefinedName();
oNewDefinedName.Name = sName;
oNewDefinedName.Ref = sDefinedNameRef;
oNewDefinedName.Ref = parserHelp.get3DRef(ws.getName(), Ref);
oNewDefinedName.bTable = true;
this.addDefinedName(oNewDefinedName);
},
......
......@@ -2054,10 +2054,8 @@ Hyperlink.prototype = {
this.bUpdateLocation = false;
if (null === this.LocationSheet || null === this.LocationRange)
this.Location = null;
else {
this.Location = (false == rx_test_ws_name.test(this.LocationSheet)) ? "'" + this.LocationSheet + "'" : this.LocationSheet;
this.Location += "!" + this.LocationRange;
}
else
this.Location = parserHelp.get3DRef(this.LocationSheet, this.LocationRange);
},
setVisited : function (bVisited) {
this.bVisited = bVisited;
......@@ -2078,13 +2076,7 @@ Hyperlink.prototype = {
},
getProperty : function (nType) {
switch (nType) {
case this.Properties.Ref:
var sRes = this.Ref.worksheet.getName();
if(false == rx_test_ws_name.test(sRes))
sRes = "'" + sRes + "'";
sRes += "!" + this.Ref.getName();
return sRes;
break;
case this.Properties.Ref: return parserHelp.get3DRef(this.Ref.worksheet.getName(), this.Ref.getName()); break;
case this.Properties.Location: return this.getLocation();break;
case this.Properties.Hyperlink: return this.Hyperlink;break;
case this.Properties.Tooltip: return this.Tooltip;break;
......
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