fpspreadsheet: support local defined names in xlsx (Note: scope not checked by fps, so far)
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9407 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
b3deb7c0f6
commit
b9a68c5f8e
@ -6,7 +6,7 @@ var
|
|||||||
wb: TsWorkbook;
|
wb: TsWorkbook;
|
||||||
ws: TsWorksheet;
|
ws: TsWorksheet;
|
||||||
cell: PCell;
|
cell: PCell;
|
||||||
i: Integer;
|
i, j: Integer;
|
||||||
fn: String;
|
fn: String;
|
||||||
begin
|
begin
|
||||||
{$IFDEF ODS}
|
{$IFDEF ODS}
|
||||||
@ -26,7 +26,7 @@ begin
|
|||||||
|
|
||||||
WriteLn('DEFINED NAMES (GLOBAL)');
|
WriteLn('DEFINED NAMES (GLOBAL)');
|
||||||
for i := 0 to wb.DefinedNames.Count-1 do
|
for i := 0 to wb.DefinedNames.Count-1 do
|
||||||
WriteLn(' ', wb.DefinedNames[i].Name, ' --> ', wb.DefinedNames[i].RangeAsString(wb));
|
WriteLn(' "', wb.DefinedNames[i].Name, '" --> ', wb.DefinedNames[i].RangeAsString(wb));
|
||||||
|
|
||||||
WriteLn('--------------------------------------------------------');
|
WriteLn('--------------------------------------------------------');
|
||||||
|
|
||||||
@ -35,6 +35,13 @@ begin
|
|||||||
ws := wb.GetWorksheetByIndex(i);
|
ws := wb.GetWorksheetByIndex(i);
|
||||||
WriteLn('WORKSHEET "', ws.Name, '"');
|
WriteLn('WORKSHEET "', ws.Name, '"');
|
||||||
|
|
||||||
|
WriteLn(' DEFINED NAMES (LOCAL)');
|
||||||
|
if ws.DefinedNames.Count = 0 then
|
||||||
|
WriteLn(' (none)')
|
||||||
|
else
|
||||||
|
for j := 0 to ws.DefinedNames.Count-1 do
|
||||||
|
WriteLn(' "', ws.DefinedNames[i].Name, '" --> ', ws.DefinedNames[i].RangeAsString(wb));
|
||||||
|
|
||||||
WriteLn(' CELLS');
|
WriteLn(' CELLS');
|
||||||
for cell in ws.Cells do
|
for cell in ws.Cells do
|
||||||
begin
|
begin
|
||||||
|
@ -17,6 +17,7 @@ begin
|
|||||||
ws := wb.AddWorksheet('Simple');
|
ws := wb.AddWorksheet('Simple');
|
||||||
wsIdx0 := wb.GetWorksheetIndex(ws);
|
wsIdx0 := wb.GetWorksheetIndex(ws);
|
||||||
|
|
||||||
|
// ... global scope
|
||||||
wb.DefinedNames.Add('distance', wsIdx0, 1, 2);
|
wb.DefinedNames.Add('distance', wsIdx0, 1, 2);
|
||||||
ws.WriteText(1, 1, 'distance'); ws.WriteNumber(1, 2, 120); ws.WriteFormula(1, 3, '=distance');
|
ws.WriteText(1, 1, 'distance'); ws.WriteNumber(1, 2, 120); ws.WriteFormula(1, 3, '=distance');
|
||||||
|
|
||||||
@ -26,6 +27,11 @@ begin
|
|||||||
wb.DefinedNames.Add('speed', wsIdx0, 3, 2);
|
wb.DefinedNames.Add('speed', wsIdx0, 3, 2);
|
||||||
ws.WriteText(3, 1, 'speed'); ws.WriteFormula(3, 2, '=distance/time');
|
ws.WriteText(3, 1, 'speed'); ws.WriteFormula(3, 2, '=distance/time');
|
||||||
|
|
||||||
|
// ... worksheet scope
|
||||||
|
ws.WriteText(4, 1, 'local'); ws.WriteNumber(4, 2, 123.456);
|
||||||
|
ws.DefinedNames.Add('local', wsIdx0, 4, 2);
|
||||||
|
ws.WriteFormula(4, 3, '=local');
|
||||||
|
|
||||||
{----------}
|
{----------}
|
||||||
|
|
||||||
// Cell range as defined name
|
// Cell range as defined name
|
||||||
|
@ -2427,6 +2427,15 @@ var
|
|||||||
defName: TsDefinedName;
|
defName: TsDefinedName;
|
||||||
begin
|
begin
|
||||||
sheet := TsWorksheet(FWorksheet);
|
sheet := TsWorksheet(FWorksheet);
|
||||||
|
|
||||||
|
// FIXME: This code does not distinguish between local and global scope!
|
||||||
|
|
||||||
|
for i := 0 to sheet.Definednames.Count-1 do
|
||||||
|
begin
|
||||||
|
defName := sheet.DefinedNames[i];
|
||||||
|
Identifiers.AddCellRangeVariable(defName.Name, defName.Range);
|
||||||
|
end;
|
||||||
|
|
||||||
book := TsWorkbook(sheet.Workbook);
|
book := TsWorkbook(sheet.Workbook);
|
||||||
for i := 0 to book.DefinedNames.Count-1 do
|
for i := 0 to book.DefinedNames.Count-1 do
|
||||||
begin
|
begin
|
||||||
|
@ -75,6 +75,7 @@ type
|
|||||||
FWorkbook: TsWorkbook;
|
FWorkbook: TsWorkbook;
|
||||||
FCells: TsCells;
|
FCells: TsCells;
|
||||||
FComments: TsComments;
|
FComments: TsComments;
|
||||||
|
FDefinedNames: TsDefinedNames;
|
||||||
FMergedCells: TsMergedCells;
|
FMergedCells: TsMergedCells;
|
||||||
FHyperlinks: TsHyperlinks;
|
FHyperlinks: TsHyperlinks;
|
||||||
FFormulas: TsFormulas;
|
FFormulas: TsFormulas;
|
||||||
@ -673,6 +674,8 @@ type
|
|||||||
property CryptoInfo: TsCryptoInfo read FCryptoInfo write FCryptoInfo;
|
property CryptoInfo: TsCryptoInfo read FCryptoInfo write FCryptoInfo;
|
||||||
{@@ List of all comment records }
|
{@@ List of all comment records }
|
||||||
property Comments: TsComments read FComments;
|
property Comments: TsComments read FComments;
|
||||||
|
{@@ List of local defined names }
|
||||||
|
property DefinedNames: TsDefinedNames read FDefinedNames;
|
||||||
{@@ List of merged cells (contains TsCellRange records) }
|
{@@ List of merged cells (contains TsCellRange records) }
|
||||||
property MergedCells: TsMergedCells read FMergedCells;
|
property MergedCells: TsMergedCells read FMergedCells;
|
||||||
{@@ List of hyperlink information records }
|
{@@ List of hyperlink information records }
|
||||||
@ -962,7 +965,7 @@ type
|
|||||||
property CryptoInfo: TsCryptoInfo read FCryptoInfo write FCryptoInfo;
|
property CryptoInfo: TsCryptoInfo read FCryptoInfo write FCryptoInfo;
|
||||||
{property RevisionsCrypto: TsCryptoInfo read FRevisionsCrypto write FRevisionsCrypto;}
|
{property RevisionsCrypto: TsCryptoInfo read FRevisionsCrypto write FRevisionsCrypto;}
|
||||||
|
|
||||||
{ Globally defined names }
|
{ Global defined names }
|
||||||
property DefinedNames: TsDefinedNames read FDefinedNames write FDefinedNames;
|
property DefinedNames: TsDefinedNames read FDefinedNames write FDefinedNames;
|
||||||
|
|
||||||
{@@ Workbook metadata}
|
{@@ Workbook metadata}
|
||||||
@ -1245,6 +1248,7 @@ begin
|
|||||||
FRows := TIndexedAVLTree.Create(@CompareRows);
|
FRows := TIndexedAVLTree.Create(@CompareRows);
|
||||||
FCols := TIndexedAVLTree.Create(@CompareCols);
|
FCols := TIndexedAVLTree.Create(@CompareCols);
|
||||||
FComments := TsComments.Create;
|
FComments := TsComments.Create;
|
||||||
|
FDefinedNames := TsDefinedNames.Create;
|
||||||
FMergedCells := TsMergedCells.Create;
|
FMergedCells := TsMergedCells.Create;
|
||||||
FHyperlinks := TsHyperlinks.Create;
|
FHyperlinks := TsHyperlinks.Create;
|
||||||
FFormulas := TsFormulas.Create;
|
FFormulas := TsFormulas.Create;
|
||||||
@ -1291,6 +1295,7 @@ begin
|
|||||||
FRows.Free;
|
FRows.Free;
|
||||||
FCols.Free;
|
FCols.Free;
|
||||||
FComments.Free;
|
FComments.Free;
|
||||||
|
FDefinedNames.Free;
|
||||||
FMergedCells.Free;
|
FMergedCells.Free;
|
||||||
FHyperlinks.Free;
|
FHyperlinks.Free;
|
||||||
FFormulas.Free;
|
FFormulas.Free;
|
||||||
|
@ -2476,7 +2476,15 @@ begin
|
|||||||
if sheetName2 = '' then sheetName2 := sheetName1;
|
if sheetName2 = '' then sheetName2 := sheetName1;
|
||||||
sheetIdx1 := book.GetWorksheetIndex(sheetName1);
|
sheetIdx1 := book.GetWorksheetIndex(sheetName1);
|
||||||
sheetIdx2 := book.GetWorksheetIndex(sheetName2);
|
sheetIdx2 := book.GetWorksheetIndex(sheetName2);
|
||||||
book.DefinedNames.Add(nameStr, sheetIdx1, sheetIdx2, r1, c1, r2, c2);
|
s := GetAttrValue(node, 'localSheetId');
|
||||||
|
if s <> '' then
|
||||||
|
begin
|
||||||
|
// local defined name
|
||||||
|
sheet := book.GetWorksheetByIndex(StrToInt(s));
|
||||||
|
sheet.DefinedNames.Add(nameStr, sheetIdx1, sheetIdx2, r1, c1, r2, c2);
|
||||||
|
end else
|
||||||
|
// global defined name
|
||||||
|
book.DefinedNames.Add(nameStr, sheetIdx1, sheetIdx2, r1, c1, r2, c2);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
node := node.NextSibling;
|
node := node.NextSibling;
|
||||||
@ -7565,6 +7573,18 @@ begin
|
|||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
for j := 0 to book.GetWorksheetCount-1 do
|
||||||
|
begin
|
||||||
|
sheet := book.GetWorksheetByIndex(j);
|
||||||
|
for i := 0 to sheet.DefinedNames.Count-1 do
|
||||||
|
begin
|
||||||
|
defName := sheet.DefinedNames[i];
|
||||||
|
sTotal := sTotal + Format('<definedName name = "%s" localSheetId="%d">%s</definedName>',
|
||||||
|
[defName.Name, i, defName.RangeAsString(FWorkbook) ]
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
// Write print ranges and repeatedly printed rows and columns
|
// Write print ranges and repeatedly printed rows and columns
|
||||||
for i := 0 to (Workbook as TsWorkbook).GetWorksheetCount-1 do
|
for i := 0 to (Workbook as TsWorkbook).GetWorksheetCount-1 do
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user