Commit f816e97e authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

Изменена функция генерации имен для автофильтров

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47121 954022d7-b5bf-4e40-9824-e11837661b57
parent 9afea02a
......@@ -1974,11 +1974,11 @@ function BinaryWorkbookTableWriter(memory, wb)
var oThis = this;
//собираем все defined names в массив
var allDefined = new Object();
if(null != this.wb.DefinedNames)
if(null != this.wb.oRealDefinedNames)
{
for(var i in this.wb.DefinedNames)
for(var i in this.wb.oRealDefinedNames)
{
var oDefinedName = this.wb.DefinedNames[i];
var oDefinedName = this.wb.oRealDefinedNames[i];
if(null == allDefined[oDefinedName.Name])
allDefined[oDefinedName.Name] = {global: oDefinedName, local: {}};
}
......@@ -3276,9 +3276,10 @@ function BinaryFileWriter(wb)
}
};
/** @constructor */
function Binary_TableReader(stream, Dxfs)
function Binary_TableReader(stream, ws, Dxfs)
{
this.stream = stream;
this.ws = ws;
this.Dxfs = Dxfs;
this.bcr = new Binary_CommonReader(this.stream);
this.Read = function(length, aTables)
......@@ -3300,6 +3301,8 @@ function Binary_TableReader(stream, Dxfs)
res = this.bcr.Read1(length, function(t,l){
return oThis.ReadTable(t,l, oNewTable);
});
if(null != oNewTable.Ref && null != oNewTable.DisplayName)
this.ws.workbook.oNameGenerator.addTableName(oNewTable.DisplayName, this.ws, oNewTable.Ref);
aTables.push(oNewTable);
}
else
......@@ -4559,7 +4562,7 @@ function Binary_WorkbookTableReader(stream, oWorkbook)
else if ( c_oSerWorkbookTypes.DefinedNames === type )
{
res = this.bcr.Read1(length, function(t,l){
return oThis.ReadDefinedNames(t,l,oThis.oWorkbook.DefinedNames);
return oThis.ReadDefinedNames(t,l);
});
}
else
......@@ -4604,13 +4607,13 @@ function Binary_WorkbookTableReader(stream, oWorkbook)
res = c_oSerConstants.ReadUnknown;
return res;
};
this.ReadDefinedNames = function(type, length, aDefinedNames)
this.ReadDefinedNames = function(type, length)
{
var res = c_oSerConstants.ReadOk;
var oThis = this;
if ( c_oSerWorkbookTypes.DefinedName == type )
{
var oNewDefinedName = new Object();
var oNewDefinedName = new DefinedName();
res = this.bcr.Read1(length, function(t,l){
return oThis.ReadDefinedName(t,l,oNewDefinedName);
});
......@@ -4620,10 +4623,16 @@ function Binary_WorkbookTableReader(stream, oWorkbook)
{
var ws = this.oWorkbook.aWorksheets[oNewDefinedName.LocalSheetId];
if(null != ws)
{
ws.DefinedNames[oNewDefinedName.Name] = oNewDefinedName;
this.oWorkbook.oNameGenerator.addLocalDefinedName(oNewDefinedName);
}
}
else
aDefinedNames[oNewDefinedName.Name] = oNewDefinedName;
{
this.oWorkbook.oNameGenerator.addDefinedName(oNewDefinedName);
this.oWorkbook.oRealDefinedNames[oNewDefinedName.Name] = oNewDefinedName;
}
}
}
else
......@@ -4831,7 +4840,7 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
}
else if ( c_oSerWorksheetsTypes.Autofilter == type )
{
var oBinary_TableReader = new Binary_TableReader(this.stream, this.Dxfs);
var oBinary_TableReader = new Binary_TableReader(this.stream, oWorksheet, this.Dxfs);
oWorksheet.AutoFilter = new Object();
res = this.bcr.Read1(length, function(t,l){
return oBinary_TableReader.ReadAutoFilter(t,l, oWorksheet.AutoFilter);
......@@ -4840,7 +4849,7 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
else if ( c_oSerWorksheetsTypes.TableParts == type )
{
oWorksheet.TableParts = new Array();
var oBinary_TableReader = new Binary_TableReader(this.stream, this.Dxfs);
var oBinary_TableReader = new Binary_TableReader(this.stream, oWorksheet, this.Dxfs);
oBinary_TableReader.Read(length, oWorksheet.TableParts);
}
else if ( c_oSerWorksheetsTypes.Comments == type )
......
......@@ -1365,6 +1365,8 @@ function Workbook(sUrlPath, eventsHandlers, oApi){
this.clrSchemeMap = GenerateDefaultColorMap();
this.DefinedNames = new Object();
this.oRealDefinedNames = new Object();
this.oNameGenerator = new NameGenerator(this);
this.TableStyles = new CTableStyles();
this.oStyleManager = new StyleManager(this);
this.calcChain = new Array();
......@@ -8285,4 +8287,54 @@ PromoteHelper.prototype = {
}
return {a0: a0, a1: a1, nX: nX};
}
};
\ No newline at end of file
};
function DefinedName(){
this.Name = null;
this.Ref = null;
this.LocalSheetId = null;
this.bTable = false;
}
function NameGenerator(wb){
this.wb = wb;
this.aExistNames = new Object();
this.sTableNamePattern = "Table";
this.nTableNameMaxIndex = 0;
};
NameGenerator.prototype = {
addName : function(sName){
this.aExistNames[sName] = 1;
},
addLocalDefinedName : function(oDefinedName){
this.addName(oDefinedName.Name);
},
addDefinedName : function(oDefinedName){
this.wb.DefinedNames[oDefinedName.Name] = oDefinedName;
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.bTable = true;
this.addDefinedName(oNewDefinedName);
},
isExist : function(sName)
{
return null != this.aExistNames[sName];
},
getNextTableName : function(ws, Ref){
this.nTableNameMaxIndex++;
var sNewName = this.sTableNamePattern + this.nTableNameMaxIndex;
while(null != this.aExistNames[sNewName])
{
this.nTableNameMaxIndex++;
sNewName = this.sTableNamePattern + this.nTableNameMaxIndex;
}
this.addTableName(sNewName, ws, Ref);
return sNewName;
}
}
\ No newline at end of file
......@@ -3343,7 +3343,7 @@
ShowRowStripes: true
},
TableColumns: tableColumns,
DisplayName: this._generateNameTable(aWs)
DisplayName: aWs.workbook.oNameGenerator.getNextTableName(aWs, ref)
};
return aWs.TableParts[aWs.TableParts.length - 1];
}
......@@ -4686,32 +4686,6 @@
};
return newObj;
},
_generateNameTable: function(aWs)
{
var number = 1;
var worksheets = aWs.workbook.aWorksheets;
for(var j = 0; j < worksheets.length; j++)
{
if(worksheets[j])
{
var table = worksheets[j].TableParts;
if(table)
{
for(var i = 0; i < table.length; i++)
{
var name = table[i].DisplayName.split('Table');
if(name[1] && !isNaN(parseFloat(name[1])))
{
if(number <= parseFloat(name[1]))
number = parseFloat(name[1]) + 1;
}
}
}
}
}
return "Table" + number;
},
_removeTableByName: function (ws, name) {
if (undefined === name) {
......
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