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,
fpszipper, {NOTE: fpszipper is the latest zipper.pp Change to standard zipper when FPC 2.4 is released. Changed by JLJR}
fpspreadsheet,
xmlread, DOM, AVL_Tree;
xmlread, DOM, AVL_Tree,math;
type
@ -142,28 +142,26 @@ var
FilePath : string;
UnZip : TUnZipper;
FileList : TStringList;
ExitSub : Boolean;
Doc : TXMLDocument;
BodyNode, SpreadSheetNode, TableNode, RowNode, CellNode : TDOMNode;
ParamRowsRepeated, ParamColsRepeated, ParamValueType, ParamFormula : string;
RowsCount, ColsCount : integer;
begin
//unzip content.xml into AFileName path
ExitSub:=false;
FilePath:=ExtractFilePath(AFileName);
FilePath:=GetTempDir(false);
UnZip:=TUnZipper.Create;
UnZip.OutputPath:=FilePath;
FileList:=TStringList.Create;
FileList.Add('content.xml');
try
Unzip.UnZipFiles(AFileName,FileList);
Except
ExitSub:=true;
finally
FreeAndNil(FileList);
FreeAndNil(UnZip);
end; //try
FileList.Free;
UnZip.Free;
if ExitSub then Exit;
Doc:=nil;
try
//process the xml file
ReadXMLFile(Doc,FilePath+'content.xml');
DeleteFile(FilePath+'content.xml');
@ -221,8 +219,9 @@ begin
TableNode:=TableNode.NextSibling;
end; //while Assigned(TableNode)
finally
Doc.Free;
end;
end;
procedure TsSpreadOpenDocReader.ReadFormula(ARow: Word; ACol : Word; ACellNode : TDOMNode);
@ -238,9 +237,15 @@ end;
procedure TsSpreadOpenDocReader.ReadNumber(ARow: Word; ACol : Word; ACellNode : TDOMNode);
var
FSettings: TFormatSettings;
Value: String;
begin
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;
{ TsSpreadOpenDocWriter }
@ -538,12 +543,19 @@ procedure TsSpreadOpenDocWriter.WriteNumber(AStream: TStream; const ARow,
ACol: Cardinal; const AValue: double);
var
StrValue: string;
DisplayStr: string;
begin
// 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);
DisplayStr:=FloatToStr(AValue);
end;
FContent := FContent +
' <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;
end;