BackgroundColor not working?

Hi,

i try to get the Background ARGB Color of a cell via:

c.GetStyle().BackgroundColor.ToArgb

As you can see in the screenshots provided the ARGB value for C2 is 0,0,0,0 (= black) whereas the cell appears White in Excel as no Color is set.

https://www.dropbox.com/s/8nxbzso21v1saul/sshot-51.png?dl=0

https://www.dropbox.com/s/af7dblz4xsgxmss/sshot-52.png?dl=0

From my Point of view 0,0,0,0 is incorrect, it should be ??,255,255,255 (don’t know the Alpha Channel).

The pattern is “None” so maybe this could be the clue that i am looking for?

Or am I thinking totally wrong?

Question is: Where do I find the ARGB ??,255,255,255 for my cell as it is White and not black…

@norman.neubert,

Thanks for the screenshot and details.

Please change your line of code to:
c.GetStyle().ForegroundColor.ToArgb

For your information, if the pattern is “Solid” or “None”, the foreground color (set/get) would be the shading color. For all other pattern types, you will use background color of the style.

See the document for your reference:

Hope, this helps a bit.

Doesn’t work, as you can see in my screenshot the foreground Color is 0,0,0,0, too.

@norman.neubert,

Well, actually your C2 cell’s color is empty, this is not white color. See the following line of code to detect if the color is empty or not:
e.g
Sample code:

bool empty = c.GetStyle().ForegroundColor.IsEmpty;

Hi Amjad,

cool, understood! Is there a emptyColor.ToARGB so i can check what the “empty Color” is?

Thanks
Norman

@norman.neubert,

Well, I think an empty color represents a color which is null or uninitialized, so you cannot determine its ARGB value.

Of course :slight_smile: i thought about a Default Color (in this case White :)). I just use 255,255,255 now and hope that Excel has no Default Color that for instance can be set to black as I do it in my Dev-Studio.

Still grinning :slight_smile:

Have a nice evening.

Kind regards
Norman

@norman.neubert

We think, Style.Pattern should fulfill your needs. Because when it returns None, then foreground colors are invalid.