Set background color of a cell in Excel worksheet using C#.NET

Hi,

it looks like that there is a bug in the Color Assignment with a Style.

I have defined a Background color like:
Dim Color_Referral As Color = Color.FromArgb(255, 217, 151, 149)
'A = 255, B = 149, G = 151 and R = 217
'Name = ffd99795
If I assign this color like_
mStyle.BackgroundColor = Color_Referral

The color of mStyle is like
A = 0, B = 149, G = 151 and R = 217
Name = d99795

Hi,


Thanks for providing us some details.

Please try to use ForegroundColor instead of BackgroundColor to set the cell’s Shading/fill color. Also set the Pattern to Solid fill. For your knowledge, the Foreground color is the cell’s outline color and Background color is the back color of the cell. But, keeping in mind, if you want to set cell’s shading color with solid fill/pattern type, you will always use ForegroundColor setter. There is no need to use Background color then that would be only useful if there is no solid/null background pattern type set for the cell. See the sample lines of code for your reference:
e.g.
Sample code:

_mStyle.ForegroundColor = Color.FromArgb(255, 217, 151, 149)
_mStyle.Pattern = BackgroundType.Solid

Hope, this helps a bit.

Thank you.