fpspreadsheet: Fix 3d formulas crashing when reading Excel2003/XML files because target sheets have not yet been loaded.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7052 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-07-18 21:38:01 +00:00
parent 8e50105ca0
commit a9ba71c6f0
2 changed files with 20 additions and 7 deletions

View File

@ -1362,17 +1362,30 @@ end;
-------------------------------------------------------------------------------}
procedure TsSpreadExcelXMLReader.ReadWorksheets(ANode: TDOMNode);
var
node: TDOMNode;
nodeName: String;
s: String;
begin
node := ANode;
// first iterate through all worksheets, get the name and add them to the
// workbook. This is because 3D formulas may refer to sheets not yet loaded.
while node <> nil do begin
nodeName := node.NodeName;
if nodeName = 'Worksheet' then begin
s := GetAttrValue(node, 'ss:Name');
if s <> '' then // the case of '' should not happen...
FWorksheet := TsWorkbook(FWorkbook).AddWorksheet(s);
end;
node := node.NextSibling;
end;
// Now iterate through the worksheets again and read their contents
while ANode <> nil do begin
nodeName := ANode.NodeName;
if nodeName = 'Worksheet' then begin
s := GetAttrValue(ANode, 'ss:Name');
if s <> '' then begin // the case of '' should not happen
FWorksheet := TsWorkbook(FWorkbook).AddWorksheet(s);
ReadWorksheet(ANode, FWorksheet);
end;
FWorksheet := TsWorkbook(FWorkbook).GetWorksheetByName(s);
ReadWorksheet(ANode, FWorksheet);
end;
ANode := ANode.NextSibling;
end;

View File

@ -89,7 +89,7 @@ type
procedure Test_Write_Read_Calc3DFormula_BIFF5;
procedure Test_Write_Read_Calc3DFormula_BIFF8;
procedure Test_Write_Read_Calc3DFormula_OOXML;
// procedure Test_Write_Read_Calc3DFormula_XML;
procedure Test_Write_Read_Calc3DFormula_XML;
procedure Test_Write_Read_Calc3DFormula_ODS;
{ Overwrite formula with other content }
@ -887,11 +887,11 @@ procedure TSpreadWriteReadFormulaTests.Test_Write_Read_Calc3DFormula_OOXML;
begin
Test_Write_Read_Calc3DFormulas(sfOOXML);
end;
{
procedure TSpreadWriteReadFormulaTests.Test_Write_Read_Calc3DFormula_XML;
begin
Test_Write_Read_Calc3DFormulas(sfExcelXML);
end; }
end;
procedure TSpreadWriteReadFormulaTests.Test_Write_Read_Calc3DFormula_ODS;
begin