You've already forked lazarus-ccr
fpspreadsheet: Introduce "settings" records for each file format to define parameters needed for reading/writing. This fixes two unit test fails in Ubuntu (only 1 fail left).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3964 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -8,7 +8,6 @@
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="spready"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<Language Value=""/>
|
||||
|
@ -614,8 +614,6 @@ type
|
||||
private
|
||||
{ Internal data }
|
||||
FWorksheets: TFPList;
|
||||
FCodePage: String;
|
||||
// FEncoding: TsEncoding;
|
||||
FFormat: TsSpreadsheetFormat;
|
||||
FBuiltinFontCount: Integer;
|
||||
FPalette: array of TsColorValue;
|
||||
@ -756,9 +754,11 @@ type
|
||||
|
||||
{@@ Identifies the "active" worksheet (only for visual controls)}
|
||||
property ActiveWorksheet: TsWorksheet read FActiveWorksheet;
|
||||
(*
|
||||
{@@ This property is only used for formats which don't support unicode
|
||||
and support a single encoding for the whole document, like Excel 2 to 5 }
|
||||
property CodePage: String read FCodePage write FCodepage;
|
||||
*)
|
||||
// property Encoding: TsEncoding read FEncoding write FEncoding;
|
||||
{@@ Retrieves error messages collected during reading/writing }
|
||||
property ErrorMsg: String read GetErrorMsg;
|
||||
@ -7030,7 +7030,6 @@ begin
|
||||
FWorksheets := TFPList.Create;
|
||||
FLog := TStringList.Create;
|
||||
FFormat := sfExcel8;
|
||||
FCodePage := GetDefaultTextEncoding;
|
||||
|
||||
FormatSettings := UTF8FormatSettings;
|
||||
FormatSettings.ShortDateFormat := MakeShortDateFormat(FormatSettings.ShortDateFormat);
|
||||
|
@ -39,6 +39,7 @@ resourcestring
|
||||
rsCircularReference = 'Circular reference found when calculating worksheet formulas';
|
||||
rsFileNotFound = 'File "%s" not found.';
|
||||
rsWorksheetNotFound = 'Worksheet "%s" not found.';
|
||||
rsWorksheetNotFound1 = 'Worksheet not found.';
|
||||
rsInvalidWorksheetName = '"%s" is not a valid worksheet name.';
|
||||
rsDefectiveInternalStructure = 'Defective internal structure of %s file.';
|
||||
rsUnknownDataType = 'Unknown data type.';
|
||||
|
@ -8,6 +8,7 @@
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="spreadtestgui"/>
|
||||
<ResourceType Value="res"/>
|
||||
<Icon Value="-1"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
@ -111,6 +112,7 @@
|
||||
<Unit15>
|
||||
<Filename Value="errortests.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="errortests"/>
|
||||
</Unit15>
|
||||
<Unit16>
|
||||
<Filename Value="virtualmodetests.pas"/>
|
||||
@ -157,9 +159,6 @@
|
||||
<DebugInfoType Value="dsDwarf2Set"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="6">
|
||||
|
@ -92,6 +92,7 @@ type
|
||||
|
||||
TsSpreadBIFF2Writer = class(TsSpreadBIFFWriter)
|
||||
private
|
||||
FSheetIndex: Integer; // Index of worksheet to be written
|
||||
procedure GetCellAttributes(ACell: PCell; XFIndex: Word;
|
||||
out Attrib1, Attrib2, Attrib3: Byte);
|
||||
{ Record writing methods }
|
||||
@ -142,6 +143,20 @@ type
|
||||
procedure WriteToStream(AStream: TStream); override;
|
||||
end;
|
||||
|
||||
TExcel2Settings = record
|
||||
// Settings used when writing to file
|
||||
DateMode: TDateMode;
|
||||
CodePage: String;
|
||||
SheetIndex: Integer;
|
||||
end;
|
||||
|
||||
var
|
||||
Excel2Settings: TExcel2Settings = (
|
||||
DateMode: dm1900;
|
||||
CodePage: 'cp1252'; // on Windows, will be replaced --> see initalization
|
||||
SheetIndex: 0;
|
||||
);
|
||||
|
||||
var
|
||||
{ the palette of the default BIFF2 colors as "big-endian color" values }
|
||||
PALETTE_BIFF2: array[$0..$07] of TsColorValue = (
|
||||
@ -1032,6 +1047,9 @@ constructor TsSpreadBIFF2Writer.Create(AWorkbook: TsWorkbook);
|
||||
begin
|
||||
inherited Create(AWorkbook);
|
||||
FLimitations.MaxPaletteSize := BIFF2_MAX_PALETTE_SIZE;
|
||||
FDateMode := Excel2Settings.DateMode;
|
||||
FCodePage := Excel2Settings.CodePage;
|
||||
FSheetIndex := Excel2Settings.SheetIndex;
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -1294,11 +1312,13 @@ procedure TsSpreadBIFF2Writer.WriteToStream(AStream: TStream);
|
||||
var
|
||||
pane: Byte;
|
||||
begin
|
||||
FWorksheet := Workbook.GetFirstWorksheet;
|
||||
FWorksheet := Workbook.GetWorksheetByIndex(FSheetIndex);
|
||||
if FWorksheet = nil then
|
||||
raise Exception.Create(rsWorksheetNotFound1);
|
||||
|
||||
WriteBOF(AStream);
|
||||
WriteFonts(AStream);
|
||||
WriteCodePage(AStream, Workbook.CodePage); //Encoding);
|
||||
WriteCodePage(AStream, FCodePage);
|
||||
WriteFormatCount(AStream);
|
||||
WriteNumFormats(AStream);
|
||||
WriteXFRecords(AStream);
|
||||
@ -2023,6 +2043,10 @@ end;
|
||||
|
||||
initialization
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
Excel2Settings.CodePage := GetDefaultTextEncoding;
|
||||
{$ENDIF}
|
||||
|
||||
RegisterSpreadFormat(TsSpreadBIFF2Reader, TsSpreadBIFF2Writer, sfExcel2);
|
||||
MakeLEPalette(@PALETTE_BIFF2, Length(PALETTE_BIFF2));
|
||||
|
||||
|
@ -116,12 +116,25 @@ type
|
||||
procedure WriteXF(AStream: TStream; AFormatRecord: PsCellFormat;
|
||||
XFType_Prot: Byte = 0); override;
|
||||
public
|
||||
constructor Create(AWorkbook: TsWorkbook); override;
|
||||
{ General writing methods }
|
||||
procedure WriteToFile(const AFileName: string;
|
||||
const AOverwriteExisting: Boolean = False); override;
|
||||
procedure WriteToStream(AStream: TStream); override;
|
||||
end;
|
||||
|
||||
TExcel5Settings = record
|
||||
DateMode: TDateMode;
|
||||
CodePage: String;
|
||||
end;
|
||||
|
||||
var
|
||||
Excel5Settings: TExcel5Settings = (
|
||||
// Settings used when writing to file
|
||||
DateMode: dm1900;
|
||||
CodePage: 'cp1252'; // on Windows, will be replaced --> see initalization
|
||||
);
|
||||
|
||||
var
|
||||
// the palette of the default BIFF5 colors as "big-endian color" values
|
||||
PALETTE_BIFF5: array[$00..$3F] of TsColorValue = (
|
||||
@ -898,6 +911,14 @@ end;
|
||||
{ TsSpreadBIFF5Writer }
|
||||
{------------------------------------------------------------------------------}
|
||||
|
||||
constructor TsSpreadBIFF5Writer.Create(AWorkbook: TsWorkbook);
|
||||
begin
|
||||
inherited Create(AWorkbook);
|
||||
FDateMode := Excel5Settings.DateMode;
|
||||
FCodePage := Excel5Settings.CodePage;
|
||||
end;
|
||||
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Writes an Excel BIFF5 file to the disc
|
||||
|
||||
@ -943,14 +964,14 @@ procedure TsSpreadBIFF5Writer.WriteToStream(AStream: TStream);
|
||||
var
|
||||
CurrentPos: Int64;
|
||||
Boundsheets: array of Int64;
|
||||
i, len: Integer;
|
||||
i: Integer;
|
||||
pane: Byte;
|
||||
begin
|
||||
{ Write workbook globals }
|
||||
|
||||
WriteBOF(AStream, INT_BOF_WORKBOOK_GLOBALS);
|
||||
|
||||
WriteCodepage(AStream, Workbook.CodePage); //WorkBook.Encoding);
|
||||
WriteCodepage(AStream, FCodePage);
|
||||
WriteWindow1(AStream);
|
||||
WriteFonts(AStream);
|
||||
WriteNumFormats(AStream);
|
||||
@ -959,13 +980,9 @@ begin
|
||||
WriteStyle(AStream);
|
||||
|
||||
// A BOUNDSHEET for each worksheet
|
||||
SetLength(Boundsheets, 0);
|
||||
SetLength(Boundsheets, Workbook.GetWorksheetCount);
|
||||
for i := 0 to Workbook.GetWorksheetCount - 1 do
|
||||
begin
|
||||
len := Length(Boundsheets);
|
||||
SetLength(Boundsheets, len + 1);
|
||||
Boundsheets[len] := WriteBoundsheet(AStream, Workbook.GetWorksheetByIndex(i).Name);
|
||||
end;
|
||||
Boundsheets[i] := WriteBoundsheet(AStream, Workbook.GetWorksheetByIndex(i).Name);
|
||||
|
||||
WriteEOF(AStream);
|
||||
|
||||
@ -1537,6 +1554,10 @@ end;
|
||||
|
||||
initialization
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
Excel5Settings.CodePage := GetDefaultTextEncoding;
|
||||
{$ENDIF}
|
||||
|
||||
RegisterSpreadFormat(TsSpreadBIFF5Reader, TsSpreadBIFF5Writer, sfExcel5);
|
||||
MakeLEPalette(@PALETTE_BIFF5, Length(PALETTE_BIFF5));
|
||||
|
||||
|
@ -166,6 +166,15 @@ type
|
||||
procedure WriteToStream(AStream: TStream); override;
|
||||
end;
|
||||
|
||||
TExcel8Settings = record
|
||||
DateMode: TDateMode;
|
||||
end;
|
||||
|
||||
var
|
||||
Excel8Settings: TExcel8Settings = (
|
||||
DateMode: dm1900;
|
||||
);
|
||||
|
||||
var
|
||||
// the palette of the 64 default BIFF8 colors as "big-endian color" values
|
||||
PALETTE_BIFF8: array[$00..$3F] of TsColorValue = (
|
||||
@ -1391,11 +1400,14 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
{ TsSpreadBIFF8Writer }
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TsSpreadBIFF8Writer }
|
||||
{------------------------------------------------------------------------------}
|
||||
|
||||
constructor TsSpreadBIFF8Writer.Create(AWorkbook: TsWorkbook);
|
||||
begin
|
||||
inherited Create(AWorkbook);
|
||||
FDateMode := Excel8Settings.DateMode;
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -1448,12 +1460,12 @@ const
|
||||
var
|
||||
CurrentPos: Int64;
|
||||
Boundsheets: array of Int64;
|
||||
i, len: Integer;
|
||||
i: Integer;
|
||||
pane: Byte;
|
||||
begin
|
||||
{ Write workbook globals }
|
||||
WriteBOF(AStream, INT_BOF_WORKBOOK_GLOBALS);
|
||||
WriteCodePage(AStream, 'ucs2le'); //seUTF16);
|
||||
WriteCodePage(AStream, 'ucs2le'); // = utf8
|
||||
WriteWindow1(AStream);
|
||||
WriteFonts(AStream);
|
||||
WriteNumFormats(AStream);
|
||||
@ -1462,13 +1474,9 @@ begin
|
||||
WriteStyle(AStream);
|
||||
|
||||
// A BOUNDSHEET for each worksheet
|
||||
SetLength(Boundsheets, 0);
|
||||
SetLength(Boundsheets, Workbook.GetWorksheetCount);
|
||||
for i := 0 to Workbook.GetWorksheetCount - 1 do
|
||||
begin
|
||||
len := Length(Boundsheets);
|
||||
SetLength(Boundsheets, len + 1);
|
||||
Boundsheets[len] := WriteBoundsheet(AStream, Workbook.GetWorksheetByIndex(i).Name);
|
||||
end;
|
||||
Boundsheets[i] := WriteBoundsheet(AStream, Workbook.GetWorksheetByIndex(i).Name);
|
||||
|
||||
WriteEOF(AStream);
|
||||
|
||||
|
@ -334,9 +334,9 @@ type
|
||||
TsSpreadBIFFWriter = class(TsCustomSpreadWriter)
|
||||
protected
|
||||
FDateMode: TDateMode;
|
||||
FCodePage: String; // in a format prepared for lconvencoding.ConvertEncoding
|
||||
FLastRow: Cardinal;
|
||||
FLastCol: Cardinal;
|
||||
FCodePage: String; // in a format prepared for lconvencoding.ConvertEncoding
|
||||
procedure CreateNumFormatList; override;
|
||||
function FindXFIndex(ACell: PCell): Integer; virtual;
|
||||
function FixColor(AColor: TsColor): TsColor; override;
|
||||
|
@ -195,6 +195,17 @@ type
|
||||
procedure WriteToStream(AStream: TStream); override;
|
||||
end;
|
||||
|
||||
|
||||
TXlsxSettings = record
|
||||
DateMode: TDateMode;
|
||||
end;
|
||||
|
||||
var
|
||||
XlsxSettings: TXlsxSettings = (
|
||||
DateMode: dm1900;
|
||||
);
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
@ -452,7 +463,7 @@ end;
|
||||
constructor TsSpreadOOXMLReader.Create(AWorkbook: TsWorkbook);
|
||||
begin
|
||||
inherited Create(AWorkbook);
|
||||
FDateMode := dm1900;
|
||||
FDateMode := XlsxSettings.DateMode;
|
||||
// Set up the default palette in order to have the default color names correct.
|
||||
Workbook.UseDefaultPalette;
|
||||
|
||||
@ -2922,7 +2933,7 @@ begin
|
||||
inherited Create(AWorkbook);
|
||||
// Initial base date in case it won't be set otherwise.
|
||||
// Use 1900 to get a bit more range between 1900..1904.
|
||||
FDateMode := dm1900;
|
||||
FDateMode := XlsxSettings.DateMode;
|
||||
|
||||
// Special version of FormatSettings using a point decimal separator for sure.
|
||||
FPointSeparatorSettings := DefaultFormatSettings;
|
||||
|
Reference in New Issue
Block a user