This project has moved. For the latest updates, please go here.

XLColor question.

Feb 17, 2012 at 2:13 PM
Edited Feb 17, 2012 at 2:20 PM

Hi, how Can I assign color to variable? Ex:

XLColor ColorMonthHeaderOdd = XLColor.FromArgb(33, 89, 103);

I get error: Error 1 Cannot implicitly convert type 'ClosedXML.Excel.IXLColor' to 'ClosedXML.Excel.XLColor'. An explicit conversion exists (are you missing a cast?)

Edit: not with var ColorMonthHeaderOdd = ......

Edit2: Solved!!!! I put a cast before:

XLColor ColorMonthHeaderOdd = (XLColor)XLColor.FromArgb(33, 89, 103);
Coordinator
Feb 17, 2012 at 4:07 PM

Remove the cast...

"Error 1 Cannot implicitly convert type 'ClosedXML.Excel.IXLColor' to 'ClosedXML.Excel.XLColor'. An explicit conversion exists (are you missing a cast?)"

Use one of the following instead:

IXLColor ColorMonthHeaderOdd = XLColor.FromArgb(33, 89, 103);

var ColorMonthHeaderOdd = XLColor.FromArgb(33, 89, 103);
Coordinator
Feb 17, 2012 at 4:18 PM

By the way, this API almost assumes you'll be using the var keyword to declare your variables. The methods and properties are designed so you don't have to care what type is being returned, just what you can reasonably do with it.

Feb 21, 2012 at 2:53 PM

Thanx, the first one work fine. I always use a ver keyword. But this time I need to whole class, and when declare:

var ColorMonthHeaderOdd = XLColor.FromArgb(33, 89, 103);

I got error: The contextual keyword 'var' may only appear within a local variable declaration.