Solid BGColor in Cells

I've read the documentation and many other posts, and I know that you say that the background color of a cell will not appear when the pattern is set to solid, but no where does it explain why.

Setting a solid background color is, in my mind, the most obvious and common use of background colors in a spreadsheet. Our client is expecting the background color to be solid, because frankly any other pattern looks ugly.

Please explain to me why you do not allow for this, especially when I can do it when working in Excel directly. Also please fix this ASAP if it is at all possible.



Hi Dan,

Thanks for considering Aspose.

Well, there are three types of color normally applied to a cell. i.e., ForegroundColor (refers to fill color or cell shading color), BackgroundColor (refers to background color, occasionally used) and Font Color (refers to font text color).

When you want to set a solid fill color (shading color) of a cell you may use ForgroundColor proper. The following code paints a yellow background color to the cell (You don't need to confuse with BackgroundColor property with it. You may use ForegroundColor property to set you desired back color of the cell. This code makes a yellow solid background) .

cell.Style.ForegroundColor = Color.Yellow;

cell.Style.Pattern = BackgroundType.Solid;

Well, BackgoundColor normally applied when you set pattern's BackgroundType (enum) to other than .None or other than .Solid. e.g.,




Here, the background fill color will be yellow with Blue Stripes in front of it.

For Font text color you may use:

cell.Style.Font.Color = Color.Red;

I write a simple example for you:

Workbook wb= new Workbook();

// If the color is not in the standard color palette you have to add it into the palette.

wb.ChangePalette(System.Drawing.Color.Thistle, 55);

Cells cells = wb.Worksheets[0].Cells;

Cell cell = cells[0,0];


int index = wb.Styles.Add();

Style style = wb.Styles[index];

//For Cell's filling color

style.ForegroundColor = Color.Thistle;

style.Pattern = BackgroundType.Solid;

// For text color

style.Font.Color = Color.Red;

style.HorizontalAlignment = TextAlignmentType.Center;

cell.Style = style;


Thank you.


Thank you so much for the quick response! I understand what you are saying...and yes I was confusing the two properties. I'll change my code to use ForegroundColor, as that is what I really want.

Thanks again, and keep up the great work!