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

Free Support Forum - aspose.com

Changing background color of cell

Hi there,

I tried to change the background color of the cell using the following code,

oWorksheet.Cells[2, 2].PutValue(“rao”);
Aspose.Cells.Style sss = oWorksheet.Cells[2, 2].GetStyle();
sss.BackgroundColor = Color.Red;
oWorksheet.Cells[2, 2].SetStyle(sss, false);

but unfortunately it doesn’t apply the background cell. Please let me know for direct property on cell to apply this without using style class.

Thanks,

Hi srinivasa,

Please use the following code snippet to set the background color of a cell.

Workbook workbook = new Workbook();
workbook.ChangePalette(System.Drawing.Color.SkyBlue, 55);
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells["A1"].Style.ForegroundColor = Color.SkyBlue;
worksheet.Cells["A1"].Style.Pattern = BackgroundType.Solid;
workbook.Save("C:\\cellBGtest.xlsx", SaveFormat.Excel97To2003);

Following link also help
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/colors-background-patterns.html

Thanks,