This project has moved and is read-only. For the latest updates, please go here.

Convert ThemeColors to RGB/Html Hex

May 30, 2012 at 6: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(

cell.Style.Fill.BackgroundColor.ThemeColor).Color;

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

 Thanks,

 smh

 

 

 


May 30, 2012 at 7: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 8:53 PM

Thanks mdeleon!! This works!!

Jan 4, 2013 at 4: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.: http://ciintelligence.blogspot.com/2012/02/converting-excel-theme-color-and-tint.html
 
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;

        }