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

Free Support Forum - aspose.com

style.ForegroundColor issue

i am running into issue for setting ForegroundColor

see line below …

Aspose.Cells.Style style = new Aspose.Cells.Style();
style.ForegroundColor = Color.Pink;

it give me error…right after i assign color.
‘style.ForegroundColor’ threw an exception of type ‘System.NullReferenceException’

it is state source from Aspose.Cells

at Aspose.Cells.Style.get_ForegroundColor()

can someone provide me some solution?


It works absolutely fine. I have tested the following code with the latest version/fix (attached), it works fine.

Sample code:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Style style = new Aspose.Cells.Style();
//OR You may also define style in this way:
//Style style = worksheet.Cells[“A1”].GetStyle();
style.ForegroundColor = Color.Pink;
style.Pattern = BackgroundType.Solid;

Please see the documents for your complete reference:

If your still could not evaluate, kindly give us your sample code to show the issue. We will check it soon.

Thank you.


I still got the same issue with the dll you provided. see 2 gif attachment. for error screen shot. and sample code i create to get those error.

i am try to apply style to range.

StyleFlag sf = new StyleFlag();
s.Pattern = BackgroundType.Solid;
s.ForegroundColor = ColorIndex(15);
sf.CellShading = true;
range1.ApplyStyle(s, sf);


thanks for the sample project with screen shots.

Please change the line of code (where you created the Style object) to:
Aspose.Cells.Style s = oWB.CreateStyle();

It works fine as I tested.

Thank you.