We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ForegroundColor and BackgroundColor not working


I am trying to apply a style to some cells:

Aspose.Cells.Style oshaTitlesData = workbook.Styles[workbook.Styles.Add()];
//Set style attributes
oshaTitlesData.ForegroundColor = Color.Aquamarine;
oshaTitlesData.BackgroundColor = Color.Blue;
oshaTitlesData.Font.IsBold = true;
oshaTitlesData.HorizontalAlignment = TextAlignmentType.Left;
//Apply this style
workbook.Worksheets[0].Cells[startRowSec1, colLongStart].SetStyle(oshaTitlesData);
workbook.Worksheets[0].Cells[startRowIncident, colLongStart].Style = oshaTitlesData;
workbook.Worksheets[0].Cells[startRowDART, colLongStart].Style = oshaTitlesData;
workbook.Worksheets[0].Cells[startRowSeverity, colLongStart].Style = oshaTitlesData;

The font and text alignment are getting correctly set, but when the Excel file generates the cells’ background color is white and the text color is black just like normal. How do I get the background fill color and the text color to change?

Christine Coder

Hi Christine Coder,

Well, the color (Aquamarine) you are applying might not be present in the Standard Color Palette (Ms Excel 97-2003), so you have to add it first into the palette before setting it as a font text or fill color of the cell. Since the Excel color palette has only 56 colors (0-55 indexed) on it, so if a color is not there, you will add the color to the palette replacing any existing color on a specified index position.

I think you may change/modify your code a bit:


//Add the color to the palette first.


Aspose.Cells.Style oshaTitlesData = workbook.Styles[workbook.Styles.Add()];
//Set style attributes

//Set the fill color of the cell as blue.

oshaTitlesData.ForegroundColor = Color.Blue;
oshaTitlesData.Pattern = BackgroundType.Solid;

//Set the font text color.

oshaTitlesData..Font.Color = Color.Aquamarine;
oshaTitlesData.Font.IsBold = true;
oshaTitlesData.HorizontalAlignment = TextAlignmentType.Left;

For further reference, please check the following:




Thank you.

I got it to work with your advice. Thanks!

Not Working

The same code is working for to set the background color only.


Although we do not evaluate issues in older version as we only recommend our users to upgrade to and try our latest APIs set as it is more robust, reliable and feature rich. Anyways, for your case (only), could you create a simple (runnable) console demo application (make it simple), zip the project and post us (with whatever the version you are using), we will check it. Also attach your template file (if any).