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

Free Support Forum - aspose.com

ForegroundColor not recognized

I’m using the evaluation copy of the latest .NET release 4.5.0 and I’m trying to set the cell .Style.ForegroundColor. If I set the color to one of the base 16 colors of Black, Red, etc., it works fine, but if I choose Color.LightGray or similar, I don’t see any change from the sheet default.

oCell.Style.ForegroundColor = Drawing.Color.Gray
oCell.Style.Pattern = Aspose.Cells.BackgroundType.Solid

Does NOT work…
oCell.Style.ForegroundColor = Drawing.Color.LightGray
oCell.Style.Pattern = Aspose.Cells.BackgroundType.Solid


Thanks for considering Aspose.

Well, the colors your are applying might not be present in the Standard Color Palette, so you have to add it first into the palette before setting it as a fill color of the cells. Since MS Excel (97-2003) color palette has only 56 colors (0-55 indexed) on it, so, if a color is not there, you will add the color to the palette replacing any existing color on a specified index position.

I think you may add a line of code:

Dim oWorkbok As Workbook = New Workbook();


' Add light gray color to the palette.

oWorkbook.ChangePalette(System.Drawing.Color.LightGray, 55)


oCell.Style.ForegroundColor = Drawing.Color.LightGray
oCell.Style.Pattern = Aspose.Cells.BackgroundType.Solid

For complete reference, please check the following:


<A href="</A></P> <P> </P> <P>Thank you.</P> <P> </P>

Then is there a way for me to look up the Palette color based on a Hex value? Or will I need to define each as a new palette color? I thought that the color pallete included all of the defined System.Drawing.Colors.