Free Support Forum - aspose.com

Setting Cell Background/Foreground color doesn't work in new version

I am currently testing out the lastest version of Aspose.Cells (3.7) for .NET.
I originally started testing out Aspose.Excel and setting the cell background/foreground color formatted correctly in my spreadsheets.
However, now that I have installed Aspose.Cells, I cannot get it to work at all. For example:

Excel e = new Excel();
int styleIndex = e.Styles.Add();
e.Styles[styleIndex].ForegroundColor = Color.Yellow;
e.Styles[styleIndex].Font.IsBold = true;
e.Styles[styleIndex].Font.Color = Color.Green;
e.Worksheets[0].Cells[1,1].PutValue(“BOOYAH!”);
e.Worksheets[0].Cells[1,1].Style = e.Styles[styleIndex];

e.Worksheets[0].Cells[2,2].Style.BackgroundColor = Color.Red;
e.Worksheets[0].Cells[2,2].PutValue(“BOOYAH2!”);

e.Worksheets[0].Cells[3,3].Style.ForegroundColor = Color.Red;
e.Worksheets[0].Cells[3,3].PutValue(“BOOYAH3!”);

e.Save(@“C:\Temp\A.xls”, FileFormatType.Default);

In this code, the text gets saved, with the bolding and coloring of the text, but setting the foreground or background property on the style does not do anything.

Can this be fixed?

Thanks,

Kyle

Hi Kyle,

Please add a line of code:

e.Styles[styleIndex].ForegroundColor = Color.Yellow;
e.Styles[StyleIndex].Pattern = BackgroundType.Solid;

e.Worksheets[0].Cells[2,2].Style.ForegroundColor = Color.Red;

e.Worksheets[0].Cells[2,2].Style.Pattern = BackgroundType.Solid;
e.Worksheets[0].Cells[2,2].PutValue("BOOYAH2!");

e.Worksheets[0].Cells[3,3].Style.ForegroundColor = Color.Red;

e.Worksheets[0].Cells[3,3].Style.Pattern = BackgroundType.Solid;

e.Worksheets[0].Cells[3,3].PutValue("BOOYAH3!");