fpspreadsheet: Allow writing duplicate filler palette entries like in the built-in Excel colors

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5867 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-05-18 15:03:20 +00:00
parent 6f8fba8ec8
commit 25da629e34
3 changed files with 28 additions and 12 deletions

View File

@@ -1230,6 +1230,11 @@ begin
SetLength(sheetPos, 0); SetLength(sheetPos, 0);
end; end;
{@@ ----------------------------------------------------------------------------
Populates the palette of the writer with the colors used by the workbook.
BIFF8 begins with the 8 default colors which are duplicated. Then the user
colors follow up to a max of total 64 entries.
-------------------------------------------------------------------------------}
procedure TsSpreadBIFF5Writer.PopulatePalette(AWorkbook: TsWorkbook); procedure TsSpreadBIFF5Writer.PopulatePalette(AWorkbook: TsWorkbook);
var var
i: Integer; i: Integer;
@@ -1240,7 +1245,9 @@ begin
// Fill up Excel colors of the standard palette to avoid empty color // Fill up Excel colors of the standard palette to avoid empty color
// place holders in Excel's colordialog. // place holders in Excel's colordialog.
for i := 16 to High(PALETTE_BIFF5) do for i := 16 to High(PALETTE_BIFF5) do
FPalette.AddUniqueColor(PALETTE_BIFF5[i]); FPalette.AddColor(PALETTE_BIFF5[i]);
// The BIFF5 palette contains duplicate colors -> don't use AddUniqueColor
// FPalette.AddUniqueColor(PALETTE_BIFF5[i]);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------

View File

@@ -2226,6 +2226,11 @@ begin
SetLength(sheetPos, 0); SetLength(sheetPos, 0);
end; end;
{@@ ----------------------------------------------------------------------------
Populates the palette of the writer with the colors used by the workbook.
BIFF8 begins with the 8 default colors which are duplicated. Then the user
colors follow up to a max of total 64 entries.
-------------------------------------------------------------------------------}
procedure TsSpreadBIFF8Writer.PopulatePalette(AWorkbook: TsWorkbook); procedure TsSpreadBIFF8Writer.PopulatePalette(AWorkbook: TsWorkbook);
var var
i: Integer; i: Integer;
@@ -2236,7 +2241,9 @@ begin
// Fill up Excel colors of the standard palette to avoid empty color // Fill up Excel colors of the standard palette to avoid empty color
// place holders in Excel's colordialog. // place holders in Excel's colordialog.
for i := 16 to High(PALETTE_BIFF8) do for i := 16 to High(PALETTE_BIFF8) do
FPalette.AddUniqueColor(PALETTE_BIFF8[i]); FPalette.AddColor(PALETTE_BIFF8[i]);
// The BIFF8 palette contains duplicate colors -> don't use AddUniqueColor
// FPalette.AddUniqueColor(PALETTE_BIFF8[i]);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------

View File

@@ -3853,11 +3853,13 @@ end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Writes the PALETTE record for the color palette. Writes the PALETTE record for the color palette.
Valid for BIFF3-BIFF8. BIFF2 has no palette in the file. Valid for BIFF3-BIFF8. BIFF2 has no palette in the file, i.e. WritePalette is
not called.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsSpreadBIFFWriter.WritePalette(AStream: TStream); procedure TsSpreadBIFFWriter.WritePalette(AStream: TStream);
const const
NUM_COLORS = 56; NUM_COLORS = 56;
MAX_PALETTE = NUM_COLORS + 8 - 1;
var var
i, n: Integer; i, n: Integer;
rgb: TsColor; rgb: TsColor;
@@ -3872,7 +3874,7 @@ begin
n := FPalette.Count; n := FPalette.Count;
{ Skip the first 8 entries - they are hard-coded into Excel } { Skip the first 8 entries - they are hard-coded into Excel }
for i := 8 to 8 + NUM_COLORS - 1 do for i := 8 to MAX_PALETTE do
begin begin
rgb := Math.IfThen(i < n, FPalette[i], $FFFFFF); rgb := Math.IfThen(i < n, FPalette[i], $FFFFFF);
AStream.WriteDWord(DWordToLE(rgb)) AStream.WriteDWord(DWordToLE(rgb))