Convert ThemeColors to RGB/Html Hex

May 30, 2012 at 5:49 PM

Hi All,

I am trying to read the background fill color of cells and when its a theme color, I'm unable to convert it to rgb or html hex value. In my code I'm doing the following:


td.BackColor = c.XLColor.FromTheme(


I'm getting an exception saying "Cannot convert theme color to Color". Is there a way around it to convert themecolor to color?






May 30, 2012 at 6:27 PM

You can get the theme colors with: workbook.Theme.Accent1.Color

Replace Accent1 with the theme you're looking for. I'll see if I can fix the color conversion. Don't wait for it though...

May 30, 2012 at 7:53 PM

Thanks mdeleon!! This works!!

Jan 4, 2013 at 3:54 PM

with your workaround, you just convert the theme color but don't apply the tint.

I found this article very usefull and it's working fine.:
Just found a litle bug in the "RgbToHls" function that not set the alpha value in the case the min and max values are equals:

if (max == min)

            hlsColor.H = 0;

            hlsColor.S = 0;

            hlsColor.L = max;

           --> **hlsColor.L = a;**
            return hlsColor;