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

Free Support Forum - aspose.com

Cells BackgroundColor definitely NOT working

hi,


I’ve seen posts regarding BackgroundColor.
Below is a portion of the vb.net code -
centering alignment works but NOT the setting row background color to Gray

Dim styleGray As Aspose.Cells.Style = objWB.Styles(objWB.Styles.Add()) 'objWS.Cells(“A13”).GetStyle()
styleGray.HorizontalAlignment = Cells.TextAlignmentType.Center
styleGray.BackgroundColor = Color.Gray
Dim flagGray As New Aspose.Cells.StyleFlag
flagGray.HorizontalAlignment = True
flagGray.CellShading = True
’ set up range
range = objWS.Cells.CreateRange(“C” & ((RowDetailStart - 1) + ni).ToString & “:” + ColMax + ((RowDetailStart - 1) + ni).ToString)
apply style
range.ApplyStyle(styleGray, flagGray)



This message was posted using Page2Forum from Aspose.Cells for .NET - Documentation
Hi,

Please use Style.ForegroundColor instead of BackgroundColor attribute. Also use Solid pattern type.

You may update your code segment a bit, see the lines in bold:

Dim styleGray As Aspose.Cells.Style = objWB.Styles(objWB.Styles.Add()) 'objWS.Cells("A13").GetStyle()
styleGray.HorizontalAlignment = Cells.TextAlignmentType.Center
styleGray.ForegroundColor = Color.Gray
styleGray.Pattern = BackgroundType.Solid
Dim flagGray As New Aspose.Cells.StyleFlag
flagGray.HorizontalAlignment = True
flagGray.CellShading = True
//............


For complete reference, please see the topic:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/colors-background-patterns.html


Thank you.

Thank you, its working now.

But the ForegroundColor method is misleading …

Hi,


Well, it is actually not misleading, it is same with MS Excel. Well, I think you might be mixing the two things foreground and background. I think you are taking foreground color as font text color or something like that, that is not like it. And, you are thinking of background color as cell shading color. For your info, Foreground color is the cell’s outline color and Background color is the back color of the cell actually. But, mind you, if you want to set a solid shading color for cells, you should use Foreground color with Solid pattern type. There is no need to use Background color then.

Hope, this helps,

Have a nice day!