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