I am trying to get the background color of some cells in an Excel worksheet in C #. I use the following code for this:
Excel.Range r = (Excel.Range)m_objRange[i, j]; int decValue = int.Parse(r.Interior.Color.ToString()); string hexValue = decValue.ToString("X");
So, I get a long decimal value, and then I convert to hex to use it in html code. Now I have a problem getting the right colors. For instance:
Case 1
Actual color is red
The returned decimal value is 255
The offset value of Hex is FF (or 0000FF)
The Corresponding Color I Received - Blue
Case 2
Actual color is blue
The returned decimal value is 16711680
Corresponding Value Hex-FF0000
The Corresponding Color I Received - Red
Case 3
Actual color is green
The returned decimal value is -32768
The corresponding value of Hex-8000
The Corresponding Color I Received - White
Now in case 1, I think I should interpret the hexadecimal value of FF as # FF0000 to get it as red? In case 3, should I interpret the hexadecimal value of 8000 as # 008000 to get green?
Is there a way in which I can get a six-digit hexadecimal value that will be exactly the color that I want? Am I getting the wrong decimal values ββor am I not converting the decimal numbers to six properly?
And what happens in case 2? Here I get a six-digit hexadecimal value, but this is completely wrong. FF0000 is clearly red, not blue.