fpspreadsheet: Fix violated file formation limitations when reading some xls files (http://www.lazarusforum.de/viewtopic.php?f=18&t=10824&start=15)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5987 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-07-24 15:18:13 +00:00
parent 0b17d047d6
commit 05bdb8bb88
4 changed files with 18 additions and 23 deletions

View File

@ -1313,24 +1313,12 @@ procedure TsSpreadBIFF2Writer.PopulatePalette(AWorkbook: TsWorkbook);
begin begin
FPalette.Clear; FPalette.Clear;
FPalette.AddBuiltinColors(false); FPalette.AddBuiltinColors(false);
// The next instruction creates an error log entry if the workbook contains { The next instruction creates an error log entry in CheckLimitations
// more colors than the default 8. This is because BIFF2 can only have a if the workbook contains more colors than the default 8.
// palette with 8 colors. This is because BIFF2 can only have a palette with 8 colors. }
FPalette.CollectFromWorkbook(AWorkbook); FPalette.CollectFromWorkbook(AWorkbook);
end; end;
(*
{@@ ----------------------------------------------------------------------------
Builds up the list of number formats to be written to the biff2 file.
Unlike biff5+ no formats are added here because biff2 supports only 21
standard formats; these formats have been added by AddBuiltInFormats.
Nothing to do here.
-------------------------------------------------------------------------------}
procedure TsSpreadBIFF2Writer.ListAllNumFormats;
begin
// Nothing to do here.
end;
*)
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Attaches cell formatting data for the given cell to the current record. Attaches cell formatting data for the given cell to the current record.
Is called from all writing methods of cell contents and rows Is called from all writing methods of cell contents and rows

View File

@ -1242,12 +1242,15 @@ begin
FPalette.Clear; FPalette.Clear;
FPalette.AddBuiltinColors(true); FPalette.AddBuiltinColors(true);
FPalette.CollectFromWorkbook(AWorkbook); FPalette.CollectFromWorkbook(AWorkbook);
// Fill up Excel colors of the standard palette to avoid empty color
// place holders in Excel's colordialog. { Fill up Excel colors of the standard palette to avoid empty color
for i := 16 to High(PALETTE_BIFF5) do place holders in Excel's colordialog. }
i := 16;
while (i <= High(PALETTE_BIFF5)) and (FPalette.Count < 64) do begin
FPalette.AddColor(PALETTE_BIFF5[i]); FPalette.AddColor(PALETTE_BIFF5[i]);
// The BIFF5 palette contains duplicate colors -> don't use AddUniqueColor // The BIFF5 palette contains duplicate colors -> don't use AddUniqueColor
// FPalette.AddUniqueColor(PALETTE_BIFF5[i]); inc(i);
end;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------

View File

@ -2238,12 +2238,15 @@ begin
FPalette.Clear; FPalette.Clear;
FPalette.AddBuiltinColors(true); FPalette.AddBuiltinColors(true);
FPalette.CollectFromWorkbook(AWorkbook); FPalette.CollectFromWorkbook(AWorkbook);
// Fill up Excel colors of the standard palette to avoid empty color
// place holders in Excel's colordialog. { Fill up Excel colors of the standard palette to avoid empty color
for i := 16 to High(PALETTE_BIFF8) do place holders in Excel's colordialog. }
i := 16;
while (i <= High(PALETTE_BIFF8)) and (FPalette.Count < 64) do begin
FPalette.AddColor(PALETTE_BIFF8[i]); FPalette.AddColor(PALETTE_BIFF8[i]);
// The BIFF8 palette contains duplicate colors -> don't use AddUniqueColor // The BIFF8 palette contains duplicate colors -> don't use AddUniqueColor
// FPalette.AddUniqueColor(PALETTE_BIFF8[i]); inc(i);
end;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------

View File

@ -1446,6 +1446,7 @@ begin
{ Read column start and end index of column range } { Read column start and end index of column range }
c1 := WordLEToN(AStream.ReadWord); c1 := WordLEToN(AStream.ReadWord);
c2 := WordLEToN(AStream.ReadWord); c2 := WordLEToN(AStream.ReadWord);
if c2 = 256 then dec(c2); // If columns are used Excel writes last index 256 - but it should be 255 ?!
{ Read col width in 1/256 of the width of "0" character } { Read col width in 1/256 of the width of "0" character }
w := WordLEToN(AStream.ReadWord); w := WordLEToN(AStream.ReadWord);