You've already forked lazarus-ccr
fpspreadsheet: Fill unused BIFF5 and BIFF8 palette entries by default colors to avoid Excel XP show an incomplete color dialog.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5863 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -111,6 +111,7 @@ type
|
|||||||
procedure AddBuiltinNumFormats; override;
|
procedure AddBuiltinNumFormats; override;
|
||||||
function FunctionSupported(AExcelCode: Integer;
|
function FunctionSupported(AExcelCode: Integer;
|
||||||
const AFuncName: String): Boolean; override;
|
const AFuncName: String): Boolean; override;
|
||||||
|
procedure PopulatePalette(AWorkbook: TsWorkbook); override;
|
||||||
procedure WriteBlank(AStream: TStream; const ARow, ACol: Cardinal;
|
procedure WriteBlank(AStream: TStream; const ARow, ACol: Cardinal;
|
||||||
ACell: PCell); override;
|
ACell: PCell); override;
|
||||||
procedure WriteBool(AStream: TStream; const ARow, ACol: Cardinal;
|
procedure WriteBool(AStream: TStream; const ARow, ACol: Cardinal;
|
||||||
@ -1308,6 +1309,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsSpreadBIFF2Writer.PopulatePalette(AWorkbook: TsWorkbook);
|
||||||
|
begin
|
||||||
|
FPalette.Clear;
|
||||||
|
FPalette.AddBuiltinColors(false);
|
||||||
|
// The next instruction creates an error log entry if the workbook contains
|
||||||
|
// more colors than the default 8. This is because BIFF2 can only have a
|
||||||
|
// palette with 8 colors.
|
||||||
|
FPalette.CollectFromWorkbook(AWorkbook);
|
||||||
|
end;
|
||||||
|
|
||||||
(*
|
(*
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Builds up the list of number formats to be written to the biff2 file.
|
Builds up the list of number formats to be written to the biff2 file.
|
||||||
|
@ -99,6 +99,7 @@ type
|
|||||||
protected
|
protected
|
||||||
function FunctionSupported(AExcelCode: Integer; const AFuncName: String): Boolean; override;
|
function FunctionSupported(AExcelCode: Integer; const AFuncName: String): Boolean; override;
|
||||||
procedure InternalWriteToStream(AStream: TStream);
|
procedure InternalWriteToStream(AStream: TStream);
|
||||||
|
procedure PopulatePalette(AWorkbook: TsWorkbook); override;
|
||||||
{ Record writing methods }
|
{ Record writing methods }
|
||||||
procedure WriteBOF(AStream: TStream; ADataType: Word);
|
procedure WriteBOF(AStream: TStream; ADataType: Word);
|
||||||
function WriteBoundsheet(AStream: TStream; AWorkSheet: TsWorksheet): Int64;
|
function WriteBoundsheet(AStream: TStream; AWorkSheet: TsWorksheet): Int64;
|
||||||
@ -1229,6 +1230,19 @@ begin
|
|||||||
SetLength(sheetPos, 0);
|
SetLength(sheetPos, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsSpreadBIFF5Writer.PopulatePalette(AWorkbook: TsWorkbook);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
FPalette.Clear;
|
||||||
|
FPalette.AddBuiltinColors(true);
|
||||||
|
FPalette.CollectFromWorkbook(AWorkbook);
|
||||||
|
// Fill up Excel colors of the standard palette to avoid empty color
|
||||||
|
// place holders in Excel's colordialog.
|
||||||
|
for i := 16 to High(PALETTE_BIFF5) do
|
||||||
|
FPalette.AddUniqueColor(PALETTE_BIFF5[i]);
|
||||||
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Writes an Excel BIFF5 file to the disc
|
Writes an Excel BIFF5 file to the disc
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ type
|
|||||||
protected
|
protected
|
||||||
function GetPrintOptions: Word; override;
|
function GetPrintOptions: Word; override;
|
||||||
procedure InternalWriteToStream(AStream: TStream);
|
procedure InternalWriteToStream(AStream: TStream);
|
||||||
procedure PopulatePalette; override;
|
procedure PopulatePalette(AWorkbook: TsWorkbook); override;
|
||||||
|
|
||||||
{ Record writing methods }
|
{ Record writing methods }
|
||||||
procedure WriteBOF(AStream: TStream; ADataType: Word);
|
procedure WriteBOF(AStream: TStream; ADataType: Word);
|
||||||
@ -2226,10 +2226,17 @@ begin
|
|||||||
SetLength(sheetPos, 0);
|
SetLength(sheetPos, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadBIFF8Writer.PopulatePalette;
|
procedure TsSpreadBIFF8Writer.PopulatePalette(AWorkbook: TsWorkbook);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
FPalette.Clear;
|
FPalette.Clear;
|
||||||
FPalette.AddBuiltinColors(true);
|
FPalette.AddBuiltinColors(true);
|
||||||
|
FPalette.CollectFromWorkbook(AWorkbook);
|
||||||
|
// Fill up Excel colors of the standard palette to avoid empty color
|
||||||
|
// place holders in Excel's colordialog.
|
||||||
|
for i := 16 to High(PALETTE_BIFF8) do
|
||||||
|
FPalette.AddUniqueColor(PALETTE_BIFF8[i]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
@ -534,7 +534,7 @@ type
|
|||||||
function GetLastColIndex(AWorksheet: TsWorksheet): Word;
|
function GetLastColIndex(AWorksheet: TsWorksheet): Word;
|
||||||
function GetPrintOptions: Word; virtual;
|
function GetPrintOptions: Word; virtual;
|
||||||
function PaletteIndex(AColor: TsColor): Word;
|
function PaletteIndex(AColor: TsColor): Word;
|
||||||
procedure PopulatePalette; virtual;
|
procedure PopulatePalette(AWorkbook: TsWorkbook); virtual;
|
||||||
|
|
||||||
// Helper function for writing the BIFF header
|
// Helper function for writing the BIFF header
|
||||||
procedure WriteBIFFHeader(AStream: TStream; ARecID, ARecSize: Word);
|
procedure WriteBIFFHeader(AStream: TStream; ARecID, ARecSize: Word);
|
||||||
@ -3074,8 +3074,7 @@ begin
|
|||||||
|
|
||||||
// Color palette
|
// Color palette
|
||||||
FPalette := TsPalette.Create;
|
FPalette := TsPalette.Create;
|
||||||
PopulatePalette;
|
PopulatePalette(AWorkbook);
|
||||||
FPalette.CollectFromWorkbook(AWorkbook);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TsSpreadBIFFWriter.Destroy;
|
destructor TsSpreadBIFFWriter.Destroy;
|
||||||
@ -3239,15 +3238,14 @@ begin
|
|||||||
Result := word(idx);
|
Result := word(idx);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadBIFFWriter.PopulatePalette;
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Populates the color palette of the BIFF writer. Must be overridden by
|
||||||
|
descendants.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
procedure TsSpreadBIFFWriter.PopulatePalette(AWorkbook: TsWorkbook);
|
||||||
begin
|
begin
|
||||||
with FPalette do
|
Unused(AWorkbook);
|
||||||
begin
|
FPalette.Clear;
|
||||||
Clear;
|
|
||||||
AddBuiltinColors(false); // 0..7
|
|
||||||
// Note: These colors cannot be edited by Excel. The format specific
|
|
||||||
// writer must duplicate these items (except for BIFF2).
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
@ -65,14 +65,6 @@ const
|
|||||||
(Format: sfOOXML; MaxRowCount: 1048576; MaxColCount: 16384; MaxCellLen: $FFFFFFFF),
|
(Format: sfOOXML; MaxRowCount: 1048576; MaxColCount: 16384; MaxCellLen: $FFFFFFFF),
|
||||||
(Format: sfOpenDocument; MaxRowCount: 1048576; MaxColCount: 1024; MaxCellLen: $FFFFFFFF)
|
(Format: sfOpenDocument; MaxRowCount: 1048576; MaxColCount: 1024; MaxCellLen: $FFFFFFFF)
|
||||||
);
|
);
|
||||||
(*
|
|
||||||
type
|
|
||||||
TTestFormat = (sfExcel2, sfExcel5, sfExcel8, sfExcelXML, sfOOXML, sfOpenDocument);
|
|
||||||
const // XLS2 XLS5 XLS8 XLSXML OOXML ODS
|
|
||||||
MAX_ROW_COUNT: array[TTestFormat] of Cardinal = (65536, 65536, 65536, 65536, 1048576, 1048576);
|
|
||||||
MAX_COL_COUNT: array[TTestFormat] of Cardinal = ( 256, 256, 256, 256, 16384, 1024);
|
|
||||||
MAX_CELL_LEN : array[TTestFormat] of Cardinal = ( 255, 255, 32767, 32767,$FFFFFFFF,$FFFFFFFF);
|
|
||||||
*)
|
|
||||||
var
|
var
|
||||||
MyWorkbook: TsWorkbook;
|
MyWorkbook: TsWorkbook;
|
||||||
MyWorksheet: TsWorksheet;
|
MyWorksheet: TsWorksheet;
|
||||||
@ -155,10 +147,10 @@ begin
|
|||||||
// Prepare a full palette
|
// Prepare a full palette
|
||||||
palette := TsPalette.Create;
|
palette := TsPalette.Create;
|
||||||
try
|
try
|
||||||
// Create random palette of 65 unique entries - 1 too many for Excel5/8
|
// Create random palette of 65 unique entries -> 1 too many for Excel5/8
|
||||||
// and a lot too many for BIFF2
|
// and a lot too many for BIFF2
|
||||||
palette.AddBuiltinColors;
|
palette.AddBuiltinColors;
|
||||||
for i:=8 to 65 do
|
for i:=palette.Count to 65 do
|
||||||
begin
|
begin
|
||||||
repeat
|
repeat
|
||||||
newColor := random(256) + random(256) shl 8 + random(256) shl 16;
|
newColor := random(256) + random(256) shl 8 + random(256) shl 16;
|
||||||
|
Reference in New Issue
Block a user