Page 1 of 1

XLSX files and modified palettes

Posted: Wed Jan 31, 2018 3:23 pm
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;

Re: XLSX files and modified palettes

Posted: Wed Feb 07, 2018 11:07 am
by larsa
Hello

Can you send me a file with a modified palette?

Re: XLSX files and modified palettes

Posted: Thu Feb 15, 2018 9:30 am
by bturcs
Thank you! I can confirm that it is working now.