Fixed bugs 2896335 and 2896338 in sf tracker.

Fixed loading of OpenDocument float values (locale independent)
Fixed loading of OpenDocument with infinite "1.#INF" value in a cell.
Decompression of "contents.xml" now tales place in local temporal user folder.


git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1002 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
Joshy
2009-11-12 20:26:02 +00:00
parent 73d227205a
commit 8c0fa3a08d

View File

@ -30,7 +30,7 @@ uses
Classes, SysUtils, Classes, SysUtils,
fpszipper, {NOTE: fpszipper is the latest zipper.pp Change to standard zipper when FPC 2.4 is released. Changed by JLJR} fpszipper, {NOTE: fpszipper is the latest zipper.pp Change to standard zipper when FPC 2.4 is released. Changed by JLJR}
fpspreadsheet, fpspreadsheet,
xmlread, DOM, AVL_Tree; xmlread, DOM, AVL_Tree,math;
type type
@ -142,28 +142,26 @@ var
FilePath : string; FilePath : string;
UnZip : TUnZipper; UnZip : TUnZipper;
FileList : TStringList; FileList : TStringList;
ExitSub : Boolean;
Doc : TXMLDocument; Doc : TXMLDocument;
BodyNode, SpreadSheetNode, TableNode, RowNode, CellNode : TDOMNode; BodyNode, SpreadSheetNode, TableNode, RowNode, CellNode : TDOMNode;
ParamRowsRepeated, ParamColsRepeated, ParamValueType, ParamFormula : string; ParamRowsRepeated, ParamColsRepeated, ParamValueType, ParamFormula : string;
RowsCount, ColsCount : integer; RowsCount, ColsCount : integer;
begin begin
//unzip content.xml into AFileName path //unzip content.xml into AFileName path
ExitSub:=false; FilePath:=GetTempDir(false);
FilePath:=ExtractFilePath(AFileName);
UnZip:=TUnZipper.Create; UnZip:=TUnZipper.Create;
UnZip.OutputPath:=FilePath; UnZip.OutputPath:=FilePath;
FileList:=TStringList.Create; FileList:=TStringList.Create;
FileList.Add('content.xml'); FileList.Add('content.xml');
try try
Unzip.UnZipFiles(AFileName,FileList); Unzip.UnZipFiles(AFileName,FileList);
Except finally
ExitSub:=true; FreeAndNil(FileList);
FreeAndNil(UnZip);
end; //try end; //try
FileList.Free;
UnZip.Free;
if ExitSub then Exit;
Doc:=nil;
try
//process the xml file //process the xml file
ReadXMLFile(Doc,FilePath+'content.xml'); ReadXMLFile(Doc,FilePath+'content.xml');
DeleteFile(FilePath+'content.xml'); DeleteFile(FilePath+'content.xml');
@ -221,9 +219,10 @@ begin
TableNode:=TableNode.NextSibling; TableNode:=TableNode.NextSibling;
end; //while Assigned(TableNode) end; //while Assigned(TableNode)
finally
Doc.Free; Doc.Free;
end; end;
end;
procedure TsSpreadOpenDocReader.ReadFormula(ARow: Word; ACol : Word; ACellNode : TDOMNode); procedure TsSpreadOpenDocReader.ReadFormula(ARow: Word; ACol : Word; ACellNode : TDOMNode);
begin begin
@ -238,9 +237,15 @@ end;
procedure TsSpreadOpenDocReader.ReadNumber(ARow: Word; ACol : Word; ACellNode : TDOMNode); procedure TsSpreadOpenDocReader.ReadNumber(ARow: Word; ACol : Word; ACellNode : TDOMNode);
var var
FSettings: TFormatSettings; FSettings: TFormatSettings;
Value: String;
begin begin
FSettings.DecimalSeparator:='.'; FSettings.DecimalSeparator:='.';
FWorkSheet.WriteNumber(Arow,ACol,StrToFloat(ACellNode.TextContent,FSettings)); Value:=GetAttrValue(ACellNode,'office:value');
if UpperCase(Value)='1.#INF' then begin
FWorkSheet.WriteNumber(Arow,ACol,1.0/0.0);
end else begin
FWorkSheet.WriteNumber(Arow,ACol,StrToFloat(GetAttrValue(ACellNode,'office:value'),FSettings));
end;
end; end;
{ TsSpreadOpenDocWriter } { TsSpreadOpenDocWriter }
@ -538,12 +543,19 @@ procedure TsSpreadOpenDocWriter.WriteNumber(AStream: TStream; const ARow,
ACol: Cardinal; const AValue: double); ACol: Cardinal; const AValue: double);
var var
StrValue: string; StrValue: string;
DisplayStr: string;
begin begin
// The row should already be the correct one // The row should already be the correct one
if IsInfinite(AValue) then begin
StrValue:='1.#INF';
DisplayStr:='1.#INF';
end else begin
Str(AValue, StrValue); Str(AValue, StrValue);
DisplayStr:=FloatToStr(AValue);
end;
FContent := FContent + FContent := FContent +
' <table:table-cell office:value-type="float" office:value="' + StrValue + '">' + LineEnding + ' <table:table-cell office:value-type="float" office:value="' + StrValue + '">' + LineEnding +
' <text:p>' + FloatToStr(AValue) + '</text:p>' + LineEnding + ' <text:p>' + DisplayStr + '</text:p>' + LineEnding +
' </table:table-cell>' + LineEnding; ' </table:table-cell>' + LineEnding;
end; end;