Cell Style vs Range Style


#1

Hello Laurence, I need help on style precendence rules.

If you set a style for a range, then set the style for a cell, it looks like it applies that style to the entire range. I was expecting it to work like Excel; I can define a style for a range then change one cell and it should take precendence.

I’m confused about how this currently works. I have 2.6.1.

How would you perform the following ?

1. Set a given range of cells to background color, then make only one cell BOLD but keep the background color.

I’m assuming a cell style uses the range name and then applies its own style in an “additive” fashion. This is how Excel works but I can’t figure out how to do this.

Also, this style seems to set background to black no matter what color I choose…

Dim style2 As Style = x._xls.Styles(x._xls.Styles.Add())
style2.Name = Me.sStyleSiteVisitsRange
style2.Font.Size = 10
style2.Pattern = BackgroundType.Solid
style2.BackgroundColor = Color.Gray

’ yields black for my range for some reason and I don’t think its a palette issue - maybe it is…

thanks
Marty


#2

Hi Marty,

Yes. Range.Style applies same style to a whole range. It saves memory and is easier and faster to process.

I will consider you request and think to make it same with MS Excel. But it will take some time to do it.

Currently you can use:

cell.Style = presetStyle

to set cells with same style.

And use

cell.Style.Font.Size = 10

to set cells with different styles.


And the background color you should change your code to

style2.ForegroundColor = Color.Gray

BackgroundColor property only takes effect when the Pattern is not BackgroundType.Solid. That’s the routine of MS Excel.