Foreground/Background Colors

I am trying to set a row’s background and foreground colors;

worksheet.Cells.Rows[0].Style.ForegroundColor = System.Drawing.Color.AliceBlue;

worksheet.Cells.Rows[0].Style.BackgroundColor = System.Drawing.Color.Bisque;

What I am getting is black color for both fore and back colors. If I put a value into any of the row’s cells

worksheet.Cells[0, 0].PutValue(“Samples”);



I will get white for back and black for fore colors. The above style setup is ignored.

I have the similar problem here. It looks like the aspose.excel doesn’t support some system color like the Color.Lime and Color.DarSeaGreen. But some others are fine

I hope that it is not the case cause colors play crutial role in my app. Can anybody from Aspose respond?

MS Excel has a default color palette. If you use a color which is not in the default color palette, you have to change the palette first. Please check `http://www.aspose.com/Products/Aspose.Excel/Api/Aspose.Excel.Excel.ChangePalette.html`.

And I think you want to use Foreground color to set font color and use Background color to set background color. Actually, in MS Excel, Background color only take effect when the background pattern is not solid.

So I think your code should change to:

Excel excel = new Excel();

excel.ChangePalette(Color.AliceBlue, 55);
excel.ChangePalette(Color.Bisque, 54);
Worksheet worksheet = excel.Worksheets[0];

worksheet.Cells.Rows[0].Style.ForegroundColor = System.Drawing.Color.AliceBlue;
worksheet.Cells.Rows[0].Style.Font.Color = System.Drawing.Color.Bisque;


worksheet.Cells[0, 0].PutValue("Samples");

I also update Aspose.Excel to make the cell inherit the row setting. Please try above code in v2.6.1 which is available at


I am almost there but not there yet; I changed the palette accordingly; I used the
worksheet.Cells.Rows[0].Style.Font.Color = System.Drawing.Color.Bisque;

to set the fore color, which is exactly what I need. But, the problem is with the background color of the cells; If I use the

worksheet.Cells.Rows[0].Style.ForegroundColor = System.Drawing.Color.AliceBlue;

for the background it shows the AliceBlue color as a background but it also paints the cell borders in this color which effectively makes them invisible.

On the other hand, if I use the

worksheet.Cells.Rows[0].Style.BackgroundColor = System.Drawing.Color.AliceBlue;

then the cell’s back color does not change (it is because it only takes effect when the background pattern is not solid, as you mentioned in your message). But, I need to use the BackgroundColor to maintain the borders visible.

To make the border visible, you can use:

worksheet.Cells.Rows[0].Style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
worksheet.Cells.Rows[0].Style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
worksheet.Cells.Rows[0].Style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
worksheet.Cells.Rows[0].Style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;

I think that the problem here is that if one uses the

worksheet.Cells.Rows[0].Style.ForegroundColor = color;

to paint the cell’s area, its background, both the cell’s area and its border are drawn in the foreground color (the ForgroundColor acts almost like the background color). As such, the cell’s border is invisible for it is drawn in the foreground color, as the rest of the cell’s area is, despite the fact that the border is set to thin is becomes invisible.

In other words, using the ForegroundColor to paint the cell’s area, its backgound, paints the cell’s barder with the foreground color as well making it invisible regardless of the cell’s border style.

Hi Roman,

If you set the Cell shading color(foreground color) in MS Excel manually, you can also find that the border is invisible.

I used the following sample code for your case:

Excel excel = new Excel();

excel.ChangePalette(Color.AliceBlue, 55);
excel.ChangePalette(Color.Bisque, 54);
Worksheet worksheet = excel.Worksheets[0];

worksheet.Cells.Rows[0].Style.ForegroundColor = System.Drawing.Color.AliceBlue;

worksheet.Cells.Rows[0].Style.BackgroundColor = System.Drawing.Color.Bisque;

worksheet.Cells.Rows[0].Style.Pattern = BackgroundType.VerticalStripe;


worksheet.Cells.Rows[0].Style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
worksheet.Cells.Rows[0].Style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
worksheet.Cells.Rows[0].Style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
worksheet.Cells.Rows[0].Style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;

worksheet.Cells[0, 0].PutValue("Samples");

it will not work. If I use the VerticalStripe pattern that is exactly what i am going to get, cells with a striped background. If I set the pattern to solid then black background is painted. Finally, if I set the pattern to none then white background is painted.

Hi Roman,

The ForegroundColor is used to set cell shading color and BackgroundColor is used to set background color only when the patter is not solid or none.

Could you create a file as your wish in MS Excel and send it to me? Thus I can understand your need more clearly. Thanks.

 <br>I am having a problem highlighting cells :<br>                   cells[i+1,j+2].Style.BackgroundColor = System.Drawing.Color.Yellow;<br><br>This did not change the color. and when i add this at the beginning of the code:<br>            excel1.ChangePalette(Color.Yellow, 51);<br>It just makes the cells totally white.<br><br><br>Someone can help with this please ?<br><br>Thanks.<br>

You don't need to change palette for yellow color is contained in the default palette.

If the background pattern is solid, you should set foreground color.

cells[i+1,j+2].Style.ForegroundColor = System.Drawing.Color.Yellow;