You've already forked lazarus-ccr
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:
@ -55,6 +55,7 @@ type
|
|||||||
|
|
||||||
TsSpreadOpenDocWriter = class(TsCustomSpreadWriter)
|
TsSpreadOpenDocWriter = class(TsCustomSpreadWriter)
|
||||||
protected
|
protected
|
||||||
|
FPointSeparatorSettings: TFormatSettings;
|
||||||
// Strings with the contents of files
|
// Strings with the contents of files
|
||||||
FMeta, FSettings, FStyles, FContent, FMimetype: string;
|
FMeta, FSettings, FStyles, FContent, FMimetype: string;
|
||||||
FMetaInfManifest: string;
|
FMetaInfManifest: string;
|
||||||
@ -72,6 +73,7 @@ type
|
|||||||
// Routines to write parts of those files
|
// Routines to write parts of those files
|
||||||
function WriteStylesXMLAsString: string;
|
function WriteStylesXMLAsString: string;
|
||||||
public
|
public
|
||||||
|
constructor Create; override;
|
||||||
{ General writing methods }
|
{ General writing methods }
|
||||||
procedure WriteStringToFile(AString, AFileName: string);
|
procedure WriteStringToFile(AString, AFileName: string);
|
||||||
procedure WriteToFile(const AFileName: string; AData: TsWorkbook;
|
procedure WriteToFile(const AFileName: string; AData: TsWorkbook;
|
||||||
@ -534,6 +536,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TsSpreadOpenDocWriter.Create;
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
|
||||||
|
FPointSeparatorSettings := SysUtils.DefaultFormatSettings;
|
||||||
|
FPointSeparatorSettings.DecimalSeparator:='.';
|
||||||
|
end;
|
||||||
|
|
||||||
{
|
{
|
||||||
Writes a string to a file. Helper convenience method.
|
Writes a string to a file. Helper convenience method.
|
||||||
}
|
}
|
||||||
@ -649,7 +659,6 @@ procedure TsSpreadOpenDocWriter.WriteNumber(AStream: TStream; const ARow,
|
|||||||
var
|
var
|
||||||
StrValue: string;
|
StrValue: string;
|
||||||
DisplayStr: string;
|
DisplayStr: string;
|
||||||
FSettings: TFormatSettings;
|
|
||||||
lStyle: string = '';
|
lStyle: string = '';
|
||||||
begin
|
begin
|
||||||
if uffBold in ACell^.UsedFormattingFields then
|
if uffBold in ACell^.UsedFormattingFields then
|
||||||
@ -660,8 +669,7 @@ begin
|
|||||||
StrValue:='1.#INF';
|
StrValue:='1.#INF';
|
||||||
DisplayStr:='1.#INF';
|
DisplayStr:='1.#INF';
|
||||||
end else begin
|
end else begin
|
||||||
FSettings.DecimalSeparator:='.';
|
StrValue:=FloatToStr(AValue,FPointSeparatorSettings); //Uses '.' as decimal separator
|
||||||
StrValue:=FloatToStr(AValue,FSettings); //Uses '.' as decimal separator
|
|
||||||
DisplayStr:=FloatToStr(AValue); // Uses locale decimal separator
|
DisplayStr:=FloatToStr(AValue); // Uses locale decimal separator
|
||||||
end;
|
end;
|
||||||
FContent := FContent +
|
FContent := FContent +
|
||||||
|
@ -262,7 +262,7 @@ type
|
|||||||
FWorkbook: TsWorkbook;
|
FWorkbook: TsWorkbook;
|
||||||
FCurrentWorksheet: TsWorksheet;
|
FCurrentWorksheet: TsWorksheet;
|
||||||
public
|
public
|
||||||
constructor Create; virtual;
|
constructor Create; virtual; // To allow descendents to override it
|
||||||
{ General writing methods }
|
{ General writing methods }
|
||||||
procedure ReadFromFile(AFileName: string; AData: TsWorkbook); virtual;
|
procedure ReadFromFile(AFileName: string; AData: TsWorkbook); virtual;
|
||||||
procedure ReadFromStream(AStream: TStream; AData: TsWorkbook); virtual;
|
procedure ReadFromStream(AStream: TStream; AData: TsWorkbook); virtual;
|
||||||
@ -288,6 +288,7 @@ type
|
|||||||
}
|
}
|
||||||
FFormattingStyles: array of TCell;
|
FFormattingStyles: array of TCell;
|
||||||
NextXFIndex: Integer; // Indicates which should be the next XF (Style) Index when filling the styles list
|
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 }
|
{ Helper routines }
|
||||||
function FindFormattingInList(AFormat: PCell): Integer;
|
function FindFormattingInList(AFormat: PCell): Integer;
|
||||||
procedure AddDefaultFormats(); virtual;
|
procedure AddDefaultFormats(); virtual;
|
||||||
@ -1141,6 +1142,11 @@ end;
|
|||||||
|
|
||||||
{ TsCustomSpreadWriter }
|
{ TsCustomSpreadWriter }
|
||||||
|
|
||||||
|
constructor TsCustomSpreadWriter.Create;
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
end;
|
||||||
|
|
||||||
{@@
|
{@@
|
||||||
Checks if the style of a cell is in the list FFormattingStyles and returns the index
|
Checks if the style of a cell is in the list FFormattingStyles and returns the index
|
||||||
or -1 if it isn't
|
or -1 if it isn't
|
||||||
|
@ -41,6 +41,7 @@ type
|
|||||||
|
|
||||||
TsSpreadOOXMLWriter = class(TsCustomSpreadWriter)
|
TsSpreadOOXMLWriter = class(TsCustomSpreadWriter)
|
||||||
protected
|
protected
|
||||||
|
FPointSeparatorSettings: TFormatSettings;
|
||||||
{ Strings with the contents of files }
|
{ Strings with the contents of files }
|
||||||
FContentTypes: string;
|
FContentTypes: string;
|
||||||
FRelsRels: string;
|
FRelsRels: string;
|
||||||
@ -59,6 +60,7 @@ type
|
|||||||
procedure WriteWorksheet(CurSheet: TsWorksheet);
|
procedure WriteWorksheet(CurSheet: TsWorksheet);
|
||||||
function GetStyleIndex(ACell: PCell): Cardinal;
|
function GetStyleIndex(ACell: PCell): Cardinal;
|
||||||
public
|
public
|
||||||
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
{ General writing methods }
|
{ General writing methods }
|
||||||
procedure WriteStringToFile(AFileName, AString: string);
|
procedure WriteStringToFile(AFileName, AString: string);
|
||||||
@ -348,6 +350,14 @@ begin
|
|||||||
else Result := 0;
|
else Result := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TsSpreadOOXMLWriter.Create;
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
|
||||||
|
FPointSeparatorSettings := DefaultFormatSettings;
|
||||||
|
FPointSeparatorSettings.DecimalSeparator := '.';
|
||||||
|
end;
|
||||||
|
|
||||||
destructor TsSpreadOOXMLWriter.Destroy;
|
destructor TsSpreadOOXMLWriter.Destroy;
|
||||||
begin
|
begin
|
||||||
SetLength(FSheets, 0);
|
SetLength(FSheets, 0);
|
||||||
@ -469,10 +479,12 @@ procedure TsSpreadOOXMLWriter.WriteNumber(AStream: TStream; const ARow,
|
|||||||
ACol: Cardinal; const AValue: double; ACell: PCell);
|
ACol: Cardinal; const AValue: double; ACell: PCell);
|
||||||
var
|
var
|
||||||
CellPosText: String;
|
CellPosText: String;
|
||||||
|
CellValueText: String;
|
||||||
begin
|
begin
|
||||||
CellPosText := TsWorksheet.CellPosToText(ARow, ACol);
|
CellPosText := TsWorksheet.CellPosToText(ARow, ACol);
|
||||||
|
CellValueText := Format('%g', [AValue], FPointSeparatorSettings);
|
||||||
FSheets[FCurSheetNum] := FSheets[FCurSheetNum] +
|
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;
|
end;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user