# How to bold a row in macro and how to auto-width columns?

Hi,

I import data into Calc (LibreOffice 6.1.2) all the time. After I do that I always do two tasks:

1. Mark whole row and bold it.
2. Mark whole file and auto-width it.

I have recorded short video what I do: https://i.imgur.com/Q5yG2kh.gif

How to write a macro to do the above tasks?

Note: I have different number of columns in every data import, so solution should take into consideration that all of the cells in the row are bolded and all of the columns are auto-widthed.

Thanks

edit retag close merge delete

Sort by » oldest newest most voted

Hello,

you've got to get a range so that you may configure it.

As you want to process all possible columns (and only the first row as for bold-ing characters), just get A1:AMJ1. Then, use this range and set it according to your needs, as shown in the code below. The first line gets the range object. The next one sets the font weight as bold. The third sets the column optimal widths.

For the record, the code processes the first sheet in the current document (ThisComponent.Sheet(0)).

Sub Main

Dim oRange As Object

oRange = ThisComponent.Sheets(0).getCellRangeByName("A1:AMJ1")
oRange.CharWeight = com.sun.star.awt.FontWeight.BOLD
oRange.Columns.OptimalWidth = True

End Sub


Best regards,

more