We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problems to set BackgroundColor of Cell

Hi!

I just tried, to set the background color of a cell. I did the same as shown in the documentation, but my cells background stays white. Maybe I forgot something important but I cannot imagine, what it could be …

Here is my code:

Style s = null;

if (tagValue > hhValue)
{
s = pWorkSheet.Cells[pYPos, 10].GetStyle();
}
else if (tagValue < llValue)
{
s = pWorkSheet.Cells[pYPos, 7].GetStyle();
}

if (s != null)
{
s.BackgroundColor = System.Drawing.Color.Red;
s.ForegroundColor = System.Drawing.Color.White;
s.Pattern = BackgroundType.Solid;

if (tagValue > hhValue)
{
pWorkSheet.Cells[pYPos, 10].SetStyle(s);
}
else if (tagValue < llValue)
{
pWorkSheet.Cells[pYPos, 7].SetStyle(s);
}
}

The style is not null, I checked that by making logfile entries if s == null. S has never been null. But The BackgroundColor is still white.

best regards,

Thomas.

Hi Thomas,

Please provide us your template file. We will look into it soon.

Thank,

Hi,

Well, The BackgroundColor would not be applied if you specify Pattern type to Solid or None. I think for your need, either you may change the Pattern to other than Solid or None, Or, you may simply use the code (delete the line: s.BackgroundColor = System.Drawing.Color.Red; and use only ForegroundColor attribute).


s.ForegroundColor = System.Drawing.Color.Red;
s.Pattern = BackgroundType.Solid;
it will work fine.


For further reference, see the topic:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/colors-background-patterns.html
and read the Note , I will quote here, i.e. "Note: If you select BackgroundType.None value from the BackgroundType enumeration, forground color will not be applied whereas background color is not applied if you select BackgroundType.None or BackgroundType.Solid value."

Feel free to contact us any time if you still have any confusion.
Thank you.

I suppose, that means, my code is correct?

My template file is the same, I uploaded in this thread

Best regards,

Thomas.


Hi Thomas,

Please check my reply and do what I have suggested.

If you still have any confusions, let us know.

Thank you.

Hi!

Now, I set the pattern to ThinDiagonalCrosshatch and that worked. Thank you very much for your help!

best regards,

Thomas.