Sep 1, 2009 at 2:59 PM
Edited Sep 1, 2009 at 3:13 PM

The following code will NOT set the FillBackgroundProperty if the foreground color has not been set previously.

            HSSFCellStyle style = _thisBook.CreateCellStyle();
            style.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.PINK.index;

It appears to be in the logic in the HSSFCellStyle.CheckDefaultBackgroundFills().  It prevents me from using the automatic foreground color with a custom background color, it even goes so far as to reset the background color if the foreground color is reset to automatic.

Is there a particular reason why you can not change the background color of a cell without changing the foreground color from automatic? 

Also, how do a set the background fill to a solid?  I see foreground fill of solid, but background all seem to be a pattern.  I don't want a pattern, I want a solid fill with no pattern.

Sep 1, 2009 at 3:19 PM

NM... I get it now.  My concept of fore and background colors was incorrect.

Sep 2, 2009 at 1:22 AM

That's ok. I used to get confused of the backgroundcolor and foregoundcolor like you while writing the fillbackground example in NPOI.Example. The Excel background is a bit more advanced than we thought. Anyway, thank you for your feedback.

If you find any bugs and issues, please feel free to let me know

Mar 20, 2010 at 12:38 PM

please kindly fix it  ..........

Mar 22, 2010 at 1:34 AM

This is not a bug. It's by design. So no need to fix it.

Sep 1, 2010 at 2:00 PM

Why is it not a bug that setting the foreground color changes the background color, and setting the background color does nothing?

Sep 1, 2010 at 5:36 PM
Edited Sep 1, 2010 at 5:37 PM

It's been a long time since I've looked at this, and if I'm wrong I hope Tony will correct me, but forecolor does not mean text color in this situation.   You have to think of the cell as having two layers that compose the background color information.  Combined they give you your final effect.  So think of the background information as a way to add a colored pattern to a cell and the foreground as the true cell color that shows through it.


I know it's confusing, but if you have excel 2007 try thinking of it this way.  When you look at the fill tab in format cells, the information on the left side deals with forecolor information, and the information on the right background.  If you pay attention to how they react with each other, it should start to give you an idea of how this all works.

Sep 1, 2010 at 6:19 PM

That makes sense, mostly :)

I have Excel 2003, and it sounds similar to 2007.  I have the choice of a "Background Color" and a "Pattern Color".

Sep 1, 2010 at 6:29 PM

Yeah, Background Color is probably really the foreground information and Pattern Color is background.

Like I said though, it can be confusing especially since most developers don't think of foreground color in this way.