Problems with colors saving to xvExcel97 format

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
Emilio
Posts: 2
Joined: Tue Apr 01, 2014 1:31 pm

Problems with colors saving to xvExcel97 format

Post by Emilio »

I have problems saving Excel files to xvExcel97 format, since some cell colors get altered in the saved file.
You can reproduce the problem slightly modifying the FormatCells demo example.

I have modified the cell background colors for the first and second default format (but the problem applies also to font colors).

Code: Select all

procedure TfrmMain.btnDefaultFormatClick(Sender: TObject);
...

  // Create first default format.
  // The sheet parameter of BeginFormat is Nil, as it's not assigned to any
  // particular woeksheet.
  XLS.CmdFormat.BeginEdit(Nil);
  //XLS.CmdFormat.Fill.BackgroundColor.RGB := $7F7F10;
  XLS.CmdFormat.Fill.BackgroundColor.RGB := 16428467;     //EMILIO MODIFIED COLOR
  XLS.CmdFormat.Font.Name := 'Courier new';
  //XLS.CmdFormat.Font.Color.RGB := 16428467;               //EMILIO MODIFIED COLOR ALSO USED FOR FONT COLOR
  XLS.CmdFormat.AddAsDefault('F1');

  // Create second default format.
  XLS.CmdFormat.BeginEdit(Nil);
  XLS.CmdFormat.Fill.BackgroundColor.RGB := 8454016;     //EMILIO MODIFIED COLOR
  //XLS.CmdFormat.Fill.BackgroundColor.RGB := $FF1010;
  XLS.CmdFormat.Font.Name := 'Ariel Black';
  //XLS.CmdFormat.Font.Color.RGB := 8454016;               //EMILIO MODIFIED COLOR ALSO USED FOR FONT COLOR
  XLS.CmdFormat.Border.Color.IndexColor := xcBlack;
  XLS.CmdFormat.Border.Style := cbsThick;
  XLS.CmdFormat.Border.Preset(cbspOutline);
  XLS.CmdFormat.AddAsDefault('F2');

...
end;
Running the program, I press the 'Use default formats' button and save to a file.
If I reopen the file with Excel (I'm using Excel 2007), I find that the cell colors have changed (not only visually, the RGB components have actually changed).
This issue occurs only if I specify the xvExcel97 format in the FormCreate event (using the default 2007 format all works fine).

Code: Select all

  XLS.Version := xvExcel97;
Can you help me? A workaround could also be useful.
I'm using Delphi 2009 and version 5.20.21 of the component.
If you need a zipped project, I can send it to you (I was unable to add attachments).

Thanks in advance
Emilio
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Problems with colors saving to xvExcel97 format

Post by larsa »

Hello

XLS (Excel 97) files can't handle RGB values. These files uses a palette of 64 predefined colors. When you uses an RGB color, the component tries to find the best match.
Lars Arvidsson, Axolot Data
Emilio
Posts: 2
Joined: Tue Apr 01, 2014 1:31 pm

Re: Problems with colors saving to xvExcel97 format

Post by Emilio »

Thanks
Emilio
Post Reply