Ask Your Question
0

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

asked 2018-10-17 13:52:46 +0200

pavion gravatar image

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2018-10-18 16:27:45 +0200

jfn gravatar image

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,

edit flag offensive delete link more

Comments

Thanks a lot. It works exactly as I need.

pavion gravatar imagepavion ( 2018-10-22 12:22:18 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-10-17 13:52:46 +0200

Seen: 99 times

Last updated: Oct 18 '18