LibreOffice 26.2 Help
By using Basic or Python programming languages it is possible to write macros that apply formats to ranges of cells in Calc.
The code snippet below creates a Sub called FormatCellBorder that applies new border formats to a given range address in the current Calc sheet.
Sub FormatCellBorder(cellAddress as String, newStyle as Byte, newWidth as Long, Optional newColor as Long)
' Creates the UNO struct that will store the new line format
Dim lineFormat as New com.sun.star.table.BorderLine2
lineFormat.LineStyle = newStyle
lineFormat.LineWidth = newWidth
If Not IsMissing(newColor) Then lineFormat.Color = newColor
' Gets the target cell
Dim oCell as Object
Set oCell = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName(cellAddress)
' Applies the new format to all borders
oCell.TopBorder = lineFormat
oCell.RightBorder = lineFormat
oCell.LeftBorder = lineFormat
oCell.BottomBorder = lineFormat
End Sub
The Sub described above takes in four arguments:
cellAddress is a string denoting the range to be formatted in the format "A1".
newStyle is an integer value that corresponds to