Cell background color is not set using DefaultFormat

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
coheris
Posts: 23
Joined: Fri Feb 16, 2018 4:24 pm

Cell background color is not set using DefaultFormat

Post by coheris »

Hello !

I'm using XLSReadWriteII 6.32 to create a XLS file ('97).
I use XLS.CmdFormat to create a default format.

In this default format, I define some properties about Alignment, Font, Border, and Fill.
In my case, I set the cell background color like this (please tell me if I'm wrong, I read that only RGB property is used in the FormatCells Sample to set background, does it mean IndexColor is not recommended ?) :

Code: Select all

XLS.CmdFormat.Fill.BackgroundColor.IndexColor := _format.FillPatternBackColor;
Then I add as default the format :

Code: Select all

XLS.CmdFormat.AddAsDefault('F' + IntToStr(formatCount));
Finally, I write in my cell with the required format like this :

Code: Select all

XLS.DefaultFormat := XLS.CmdFormat.Defaults.Find('F' + IntToStr(_fmtIdx));
XLS[curSheet].AsFloat[_col, _row] := _number;
And when I open my document, everything is fine about alignment, font, and border, but my background color is not set.

Thank you and best regards.
coheris
Posts: 23
Joined: Fri Feb 16, 2018 4:24 pm

Re: Cell background color is not set using DefaultFormat

Post by coheris »

Hi,

Do you have any news about this issue ?

Best regards.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Cell background color is not set using DefaultFormat

Post by larsa »

Hello

No, I can't reproduce this. Here is the code I used:

Code: Select all

XLS.CmdFormat.BeginEdit(FXSS.XLS[0]);
XLS.CmdFormat.Fill.BackgroundColor.IndexColor := xcBlue;
XLS.CmdFormat.AddAsDefault('F1');

XLS.DefaultFormat := FXSS.XLS.CmdFormat.Defaults.Find('F1');
XLS[0].AsFloat[1,1] := 125
Please include code samples that will compile. It's then much easier to see what may be wrong.
Lars Arvidsson, Axolot Data
coheris
Posts: 23
Joined: Fri Feb 16, 2018 4:24 pm

Re: Cell background color is not set using DefaultFormat

Post by coheris »

Hi !

I've now been able to fix the issue (which was ours :) )
I don't know how or why, but with XLSRWII 6, what was considered as FillPatternForeColor in our application is now the FillPatternBackgroundColor.
So obviously the background color wasn't set as I didn't update the right property...

Thank you and best regards.
Post Reply