How to get style object from range

Hi,

I have a range defined in sheet, hence I get the range object by calling
worksheets.getRangeByName(“rangename”);
which returns range object. I would like to apply the style for this range. so I have to create (Is it ideal to create the style for every range? because I will only be changing referesTo for new range)the style object and set the respective style flag. then the styling will get applied to range. perfect.

Now I would like to get the style applied to range. But range object don’t have any getStyle method. How to achieve this?


Regards,
Azhar

Hi,

Well, you are doing fine i.e. create style object for the range, specify your desired formattings, create style flag object and set the respective formattings on, now apply the style to the range, it is ok.

Well, since a range may involve more than one cell and cells might have different formattings, so there is no getStyle() method for a Range object. You may scan through the individual cells by using Range.get(row, column) method that will return you a Cell object so you should use its getStyle() here. Also, there are some quite useful methods for the Range object i.e. getFirstRow(), getFirstColumn(), getRowCount(), getColumnCount() etc. which you may use and loop through to get the range area (cells) for your needs.

See the document for your complete reference:
Named Ranges

Thank you.

Well, I agree cells might have different formatting but excel does this.

select the range of cells and apply bold formatting on it.

when you select those range again, on formatting toolbar you could see bold highlighted. I am looking for same kind of behavior.

Regards,
Azhar




Hi,


Well, I am afraid, there is no such feature (get Range style in on go) available at the moment. Please try using the approach as I devised in my previous post.

Thank you.

well, the approach is not appropriate for me. anyway thanks for the update.

Regards,
Azhar