XLSX files and modified palettes

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
bturcs
Posts: 23
Joined: Tue Nov 14, 2017 9:28 am

XLSX files and modified palettes

Post by bturcs »

For backwards compatibility we still use indexed palettes. Unfortunately when saving the XLSX files with modified palettes, the palette gets not saved and the XLS file will have different colors than specified. I found the following workaround to generate the palette before saving the file. Is there a better solution?

Code: Select all

uses XlsReadWriteII5, XLSCmdFormat5, Xc12Utils5, Xc12DataStyleSheet5, SysUtils, Graphics;

procedure TestIndexColor;
var
  LDoc: TXLSReadWriteII5;
  LFormat: TXLSCmdFormat;
  I: Integer;
const
  LColor = $07C1FF;
begin
  try
    LDoc := TXLSReadWriteII5.Create(nil);
    LDoc.Palette[9] := $07C1FF;
    LDoc.Sheets[0].AsString[3, 3] := 'Hello!';
    LFormat := LDoc.CmdFormat;
    LFormat.BeginEdit(LDoc[0]);
    LFormat.Fill.BackgroundColor.IndexColor := TXc12IndexColor(9);
    LFormat.Apply(3, 3);
    LDoc.Filename := 'C:\TEMP\COLOR.XLSX';

    // Workaround
    for I := 0 to High(Xc12IndexColorPalette) do
      LDoc.Manager.StyleSheet.InxColors.Add.RGB := //
        ((LDoc.Palette[I] shl 16) and $FF0000) or //
        (LDoc.Palette[I] and $00FF00) or //
        ((LDoc.Palette[I] shr 16) and $0000FF);

    LDoc.Write;
  finally
    freeAndNil(LDoc);
  end;
end;
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: XLSX files and modified palettes

Post by larsa »

Hello

Can you send me a file with a modified palette?
Lars Arvidsson, Axolot Data
bturcs
Posts: 23
Joined: Tue Nov 14, 2017 9:28 am

Re: XLSX files and modified palettes

Post by bturcs »

Thank you! I can confirm that it is working now.
Post Reply