How to set background color of a cell

I am trying to set background of cell to solid red. Leaving the foreground color as it is.

Below id my code. But in the output file i don’t see the color is changing

Workbook wb = new Workbook(@“C:\Test.xlsx”);
var style = wb.Worksheets[0].Cells[“A2”].GetStyle();
style.Pattern = BackgroundType.Solid;
style.BackgroundColor = System.Drawing.Color.Red;
wb.Worksheets[0].Cells[“A2”].SetStyle(style);
wb.Save(@“C:\Test2.xlsx”);


Hi,

Thanks for your posting and using Aspose.Cells.

Please use the Style.ForegroundColor property instead. Please see the following code. I have attached the output xlsx file generated by it for your reference.

C#


Workbook wb = new Workbook(@“Test.xlsx”);

var style = wb.Worksheets[0].Cells[“A2”].GetStyle();

style.Pattern = BackgroundType.Solid;

style.ForegroundColor = System.Drawing.Color.Red;

wb.Worksheets[0].Cells[“A2”].SetStyle(style);

wb.Save(@“Test2.xlsx”);