How to set the background color of a cell in Excel worksheet in .NET

I am having trouble setting the background color on cells. I get the font to change colors, I just get WHITE cells when i attemp to change the background color. I also tried to add the color to the pallet and set it that way, and same results.

Here is an except from my code:

Dim wb As Workbook = New Workbook()

wb.Open(Server.MapPath(Request.ApplicationPath) & "\Excel\ExcelTemplate.xls")

Dim ogsheet As Worksheet = wb.Worksheets("LENDER")

Dim Sheet As Worksheet

Sheet.Cells.Item(1, 1).PutValue(HeaderStr)

Sheet.Cells.Item(1, 1).Style.Font.Color = (System.Drawing.Color.Blue)

Sheet.Cells.Item(1, 1).Style.BackgroundColor = (System.Drawing.Color.Red)

-=-=-=-=-=-=-=-=-----------=-=-=-=-=-==--==-=-=-=-=-=-=-=-

Also tried this:

wb.ChangePalette(System.Drawing.Color.FromArgb(Red, Blue, Green), 55)

Sheet.Cells.Item(row, col).Style.BackgroundColor = System.Drawing.Color.FromArgb( Red, Green, Blue)

My red blue green are int values.

Thanks,

michael

Hi Michael,

If you want to set the filling color of the cells, you may use Style.ForegroundColor property with Style.Pattern property.

Please change your code to:

.............

Sheet.Cells.Item(1, 1).Style.Font.Color = (System.Drawing.Color.Blue)

Sheet.Cells.Item(1, 1).Style.ForegroundColor = (System.Drawing.Color.Red)

Sheet.Cells.Item(1, 1).Style.Pattern = BackgroundType.Solid

For further ref. please docs topic:

https://docs.aspose.com/display/cellsnet/Cells+Formatting

Hopefully it will give you some insight about setting colors to cells.

Thank you.