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
This commit is contained in:
sekelsenmat
2012-04-27 08:01:15 +00:00
parent a24299c185
commit 0ee4ede6b0
3 changed files with 31 additions and 5 deletions

View File

@ -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 +

View File

@ -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

View File

@ -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(' <c r="%s" s="0" t="n"><v>%f</v></c>', [CellPosText, AValue]) + LineEnding;
Format(' <c r="%s" s="0" t="n"><v>%s</v></c>', [CellPosText, CellValueText]) + LineEnding;
end;
{