fpspreadsheet: Fix ooxml reader crashing for files having no shared strings table.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3379 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-07-25 16:46:39 +00:00
parent 005434006f
commit 11772b0156
5 changed files with 22 additions and 16 deletions

View File

@@ -93,16 +93,13 @@
<FormatVersion Value="1"/> <FormatVersion Value="1"/>
</local> </local>
</RunParams> </RunParams>
<RequiredPackages Count="3"> <RequiredPackages Count="2">
<Item1> <Item1>
<PackageName Value="laz_fpspreadsheet"/> <PackageName Value="laz_fpspreadsheet_visual"/>
</Item1> </Item1>
<Item2> <Item2>
<PackageName Value="laz_fpspreadsheet_visual"/>
</Item2>
<Item3>
<PackageName Value="LCL"/> <PackageName Value="LCL"/>
</Item3> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="2"> <Units Count="2">
<Unit0> <Unit0>

View File

@@ -4,7 +4,7 @@ program spready;
uses uses
Interfaces, // this includes the LCL widgetset Interfaces, // this includes the LCL widgetset
Forms, mainform, laz_fpspreadsheet_visual, laz_fpspreadsheet; Forms, mainform, laz_fpspreadsheet_visual;
{$R *.res} {$R *.res}

View File

@@ -25,7 +25,7 @@
This package is all you need if you don't want graphical components (like grids and charts)."/> This package is all you need if you don't want graphical components (like grids and charts)."/>
<License Value="LGPL with static linking exception. This is the same license as is used in the LCL (Lazarus Component Library)."/> <License Value="LGPL with static linking exception. This is the same license as is used in the LCL (Lazarus Component Library)."/>
<Version Major="1" Minor="2"/> <Version Major="1" Minor="2"/>
<Files Count="22"> <Files Count="23">
<Item1> <Item1>
<Filename Value="fpolestorage.pas"/> <Filename Value="fpolestorage.pas"/>
<UnitName Value="fpolestorage"/> <UnitName Value="fpolestorage"/>
@@ -114,6 +114,10 @@ This package is all you need if you don't want graphical components (like grids
<Filename Value="fpsfunc.pas"/> <Filename Value="fpsfunc.pas"/>
<UnitName Value="fpsfunc"/> <UnitName Value="fpsfunc"/>
</Item22> </Item22>
<Item23>
<Filename Value="fpsxmlcommon.pas"/>
<UnitName Value="fpsxmlcommon"/>
</Item23>
</Files> </Files>
<RequiredPkgs Count="2"> <RequiredPkgs Count="2">
<Item1> <Item1>

View File

@@ -11,7 +11,7 @@ uses
xlsbiff5, xlsbiff8, xlsxooxml, fpsutils, fpsStreams, fpszipper, xlsbiff5, xlsbiff8, xlsxooxml, fpsutils, fpsStreams, fpszipper,
uvirtuallayer_types, uvirtuallayer, uvirtuallayer_ole, uvirtuallayer_types, uvirtuallayer, uvirtuallayer_ole,
uvirtuallayer_ole_helpers, uvirtuallayer_ole_types, uvirtuallayer_stream, uvirtuallayer_ole_helpers, uvirtuallayer_ole_types, uvirtuallayer_stream,
fpolebasic, xlscommon, wikitable, fpsNumFormatParser, fpsfunc; fpolebasic, xlscommon, wikitable, fpsNumFormatParser, fpsfunc, fpsxmlcommon;
implementation implementation

View File

@@ -448,6 +448,7 @@ var
FileList : TStringList; FileList : TStringList;
SheetList: TStringList; SheetList: TStringList;
i: Integer; i: Integer;
fn: String;
BodyNode, SpreadSheetNode, TableNode: TDOMNode; BodyNode, SpreadSheetNode, TableNode: TDOMNode;
StylesNode: TDOMNode; StylesNode: TDOMNode;
@@ -478,10 +479,12 @@ begin
SheetList := TStringList.Create; SheetList := TStringList.Create;
try try
// process the sharedStrings.xml file // process the sharedStrings.xml file
if FileExists(FilePath + OOXML_PATH_XL_STRINGS) then begin
ReadXMLFile(Doc, FilePath + OOXML_PATH_XL_STRINGS); ReadXMLFile(Doc, FilePath + OOXML_PATH_XL_STRINGS);
DeleteFile(FilePath + OOXML_PATH_XL_STRINGS); DeleteFile(FilePath + OOXML_PATH_XL_STRINGS);
ReadSharedStrings(Doc.DocumentElement.FindNode('si')); ReadSharedStrings(Doc.DocumentElement.FindNode('si'));
FreeAndNil(Doc); FreeAndNil(Doc);
end;
// process the styles.xml file // process the styles.xml file
ReadXMLFile(Doc, FilePath + OOXML_PATH_XL_STYLES); ReadXMLFile(Doc, FilePath + OOXML_PATH_XL_STYLES);
@@ -507,7 +510,9 @@ begin
// unzip sheet file // unzip sheet file
FileList := TStringList.Create; FileList := TStringList.Create;
try try
FileList.Add(OOXML_PATH_XL_WORKSHEETS + SheetList[i] + '.xml'); // The file name is always "sheet<n>.xml", irrespective of the sheet's name!
fn := OOXML_PATH_XL_WORKSHEETS + 'sheet' + IntToStr(i+1) + '.xml';
FileList.Add(fn);
UnZip := TUnZipper.Create; UnZip := TUnZipper.Create;
try try
UnZip.OutputPath := FilePath; UnZip.OutputPath := FilePath;
@@ -519,8 +524,8 @@ begin
FreeAndNil(FileList); FreeAndNil(FileList);
end; end;
ReadXMLFile(Doc, FilePath + OOXML_PATH_XL_WORKSHEETS + SheetList[i] + '.xml'); ReadXMLFile(Doc, FilePath + fn);
DeleteFile(FilePath + OOXML_PATH_XL_WORKSHEETS + SheetList[i] + '.xml'); DeleteFile(FilePath + fn);
FWorksheet := AData.AddWorksheet(SheetList[i]); FWorksheet := AData.AddWorksheet(SheetList[i]);