Hi,
Thanks for considering Aspose.
When you use Style.ForegroundColor / Style.BackgroundColor properties, you have to set the Pattern property as well. Please read the description / explanation below for your reference.
Explanation:
In MS Excel 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 of a cell).
When you want to set a solid fill color (shading color) of a cell you may use ForgroundColor property. 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.,
worksheet.Cells["A2"].Style.ForegroundColor=Color.Blue;
worksheet.Cells["A2"].Style.BackgroundColor=Color.Yellow;
worksheet.Cells["A2"].Style.Pattern=BackgroundType.VerticalStripe;
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. For your info, standard color palette has 56 colors (0-55) indexed
wb.ChangePalette(System.Drawing.Color.SkyBlue, 55);
Cells cells = wb.Worksheets[0].Cells;
Cell cell = cells[0,0];
cell.PutValue("Testing");
int index = wb.Styles.Add();
Style style = wb.Styles[index];
//For Cell's filling color
style.ForegroundColor = System.Drawing.Color.SkyBlue;
style.Pattern = BackgroundType.Solid;
// For text color
style.Font.Color = Color.White;
style.HorizontalAlignment = TextAlignmentType.Center;
cell.Style = style;
wb.Save("d:\\test\\testclr.xls");
Hoping you got it!
Thank you.