We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Howto Set the Font Color to a custom value in a cell IStyle

I am working on exporting a SfDatagrid in Excel. I'm implementing cell styles to be able to modify the aspects of the various cells in excel to reflect the SfDataGrid coloring.
As stated in the Subject, I've found how to set the background color, the border and font size and type.
Unfortunately there is no way to set the Foreground of the cell in the style and the font color asks for an "ExcelKnownColor".

Is there a way to convert a custom html format color like "#FFCCEE" to an "ExcelKnownColor"? I'm sure that excel is able to get any kind of RGB combination of colors so this enumeration is really strange to use.

it would be nice to have a Foreground color property in the IStyle similar to the one used for the cell background color.

thank you in advance

1 Reply

KD Kesavan D Syncfusion Team July 20, 2016 07:33 AM UTC

Hi Sabrina, 

Thank you for contacting Syncfusion support. 

XlsIO allows to set custom colors in CellStyle and Font as shown in the below code sample. 

Code snippet: 

    //Set custom font color 
    worksheet.Range["A1"].CellStyle.Font.RGBColor = System.Drawing.ColorTranslator.FromHtml("#FFCCEE"); 
    worksheet.Range["A1"].Text = "Color"; 
    //Set custom cell style color 
    worksheet.Range["A2"].CellStyle.Color = System.Drawing.ColorTranslator.FromHtml("#FFCCEE"); 

We have prepared a sample which illustrates the same and can be downloaded from the below link. 

Kindly verify the sample and let us know if your requirement is fulfilled. 


Live Chat Icon For mobile
Up arrow icon