# macro to remove bold from a particular range in all sheets

Hello. I am trying to write a macro using LibO 4.4.3 on Linux 64 bit.

In the 14th column of all sheets, from rows 4 to 45, it should make only the cells with content "अमावास्या" and "पौर्णमासी" bold and remove bold from all other cells. However, I am totally stumped as to how to access the font etc attributes from BASIC. Please help!

This is my attempt going as far as getting the requisite cell object but after that I'm at a loss:

sub boldenPurniAma
sheets = ThisComponent.Sheets
for each sheet in sheets
for row = 4 to 45
c = sheet.getCellByPosition(14,row)
' what should I do here?
next row
next sheet
end sub


Thanks!

edit retag close merge delete

Sort by » oldest newest most voted

Hi - Something like this:

sub boldenPurniAma

dim oSheets as object, oSheet as object, oCell as object
dim lRow as long

oSheets = ThisComponent.Sheets

for each oSheet in oSheets

' Beware, lines/cols are numbered from zero'

for lRow = 3 to 44
oCell = oSheet.getCellByPosition(13, lRow)
oCell.charWeight = com.sun.star.awt.FontWeight.NORMAL
next lRow

next oSheet

end sub


See documentation here and here

But you can simply do:

sub boldenPurniAma2

dim oSheets as object, oSheet as object, oRange as object

oSheets = ThisComponent.Sheets

for each oSheet in oSheets

' Beware, the lines are numbered from zero'

oRange = oSheet.getCellRangeByPosition(13, 4, 13, 44)
oRange.charWeight = com.sun.star.awt.FontWeight.NORMAL

next oSheet

end sub


Regards

more

Hi thanks a lot for your kind reply! I agree that the reference lists the properties you mention but I searched a lot and wasn't sure where to refer to if I just, say, wanted to know what members a cell has, or a cell range has for that matter. Can you clarify that?

Note that I still need to know how to identify the text content of a cell based on which I have to make it bold (the second part of my question).

( 2015-05-27 09:28:27 +0200 )edit

Sorry I missed that part of the question. This wiki page includes links to various resources including guides and Xray tool that I use.

( 2015-05-27 10:06:49 +0200 )edit

I now tried your solution (and thanks for the ref to Xray). But it does not work as desired. The cell font attribute is indeed changed, but my font comes in regular weight only and the bold is a faux-bold which apparently cannot be enabled by setting the charWeight. Any idea how to set faux bold?

( 2015-05-27 15:06:48 +0200 )edit

Sorry, I do not know what it is. Maybe is it just the font that is bold by default: e.g. Segoe UI Semibold, Arial Black, Impact...

( 2015-05-27 15:23:06 +0200 )edit