From 0ee4ede6b0b5bf83b61df9dfc0f80d7148639457 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Fri, 27 Apr 2012 08:01:15 +0000 Subject: [PATCH] fpspreadsheet: Fixes using always point for numbers in OOXML and adds a solution to initialize the format settings in the constructor of the writer git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2410 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/fpsopendocument.pas | 14 +++++++++++--- components/fpspreadsheet/fpspreadsheet.pas | 8 +++++++- components/fpspreadsheet/xlsxooxml.pas | 14 +++++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 37ba898ec..c91ae8b45 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -55,6 +55,7 @@ type TsSpreadOpenDocWriter = class(TsCustomSpreadWriter) protected + FPointSeparatorSettings: TFormatSettings; // Strings with the contents of files FMeta, FSettings, FStyles, FContent, FMimetype: string; FMetaInfManifest: string; @@ -72,6 +73,7 @@ type // Routines to write parts of those files function WriteStylesXMLAsString: string; public + constructor Create; override; { General writing methods } procedure WriteStringToFile(AString, AFileName: string); procedure WriteToFile(const AFileName: string; AData: TsWorkbook; @@ -534,6 +536,14 @@ begin end; end; +constructor TsSpreadOpenDocWriter.Create; +begin + inherited Create; + + FPointSeparatorSettings := SysUtils.DefaultFormatSettings; + FPointSeparatorSettings.DecimalSeparator:='.'; +end; + { Writes a string to a file. Helper convenience method. } @@ -649,7 +659,6 @@ procedure TsSpreadOpenDocWriter.WriteNumber(AStream: TStream; const ARow, var StrValue: string; DisplayStr: string; - FSettings: TFormatSettings; lStyle: string = ''; begin if uffBold in ACell^.UsedFormattingFields then @@ -660,8 +669,7 @@ begin StrValue:='1.#INF'; DisplayStr:='1.#INF'; end else begin - FSettings.DecimalSeparator:='.'; - StrValue:=FloatToStr(AValue,FSettings); //Uses '.' as decimal separator + StrValue:=FloatToStr(AValue,FPointSeparatorSettings); //Uses '.' as decimal separator DisplayStr:=FloatToStr(AValue); // Uses locale decimal separator end; FContent := FContent + diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index 14e36f6c1..e1dbdfe7d 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -262,7 +262,7 @@ type FWorkbook: TsWorkbook; FCurrentWorksheet: TsWorksheet; public - constructor Create; virtual; + constructor Create; virtual; // To allow descendents to override it { General writing methods } procedure ReadFromFile(AFileName: string; AData: TsWorkbook); virtual; procedure ReadFromStream(AStream: TStream; AData: TsWorkbook); virtual; @@ -288,6 +288,7 @@ type } FFormattingStyles: array of TCell; NextXFIndex: Integer; // Indicates which should be the next XF (Style) Index when filling the styles list + constructor Create; virtual; // To allow descendents to override it { Helper routines } function FindFormattingInList(AFormat: PCell): Integer; procedure AddDefaultFormats(); virtual; @@ -1141,6 +1142,11 @@ end; { TsCustomSpreadWriter } +constructor TsCustomSpreadWriter.Create; +begin + inherited Create; +end; + {@@ Checks if the style of a cell is in the list FFormattingStyles and returns the index or -1 if it isn't diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas index 8b6fcc3e4..170b39350 100755 --- a/components/fpspreadsheet/xlsxooxml.pas +++ b/components/fpspreadsheet/xlsxooxml.pas @@ -41,6 +41,7 @@ type TsSpreadOOXMLWriter = class(TsCustomSpreadWriter) protected + FPointSeparatorSettings: TFormatSettings; { Strings with the contents of files } FContentTypes: string; FRelsRels: string; @@ -59,6 +60,7 @@ type procedure WriteWorksheet(CurSheet: TsWorksheet); function GetStyleIndex(ACell: PCell): Cardinal; public + constructor Create; override; destructor Destroy; override; { General writing methods } procedure WriteStringToFile(AFileName, AString: string); @@ -348,6 +350,14 @@ begin else Result := 0; end; +constructor TsSpreadOOXMLWriter.Create; +begin + inherited Create; + + FPointSeparatorSettings := DefaultFormatSettings; + FPointSeparatorSettings.DecimalSeparator := '.'; +end; + destructor TsSpreadOOXMLWriter.Destroy; begin SetLength(FSheets, 0); @@ -469,10 +479,12 @@ procedure TsSpreadOOXMLWriter.WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); var CellPosText: String; + CellValueText: String; begin CellPosText := TsWorksheet.CellPosToText(ARow, ACol); + CellValueText := Format('%g', [AValue], FPointSeparatorSettings); FSheets[FCurSheetNum] := FSheets[FCurSheetNum] + - Format(' %f', [CellPosText, AValue]) + LineEnding; + Format(' %s', [CellPosText, CellValueText]) + LineEnding; end; {