Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

your crumpy code works for me with LO5.3.0.3 Linux, but anyway … I dit some clean up:

sub FormatRange()

   doc = ThisComponent
   Sheet = doc.CurrentController.ActiveSheet
   StyleFamilies = doc.StyleFamilies
   CellStyles = StyleFamilies.getByName("CellStyles")

   If not CellStyles.hasByName("MyTestStyle") Then
       NewStyle = Doc.createInstance("com.sun.star.style.CellStyle")
       CellStyles.insertByName("MyTestStyle", NewStyle)
   With NewStyle
       .ParentStyle = "Default"
       .CharWeight = com.sun.star.awt.FontWeight.BOLD
       .CharFontName = "Courier"
       .HoriJustify = 2        
       .CharHeight = 12
       .CellBackColor = RGB(255,141,56)
    End With
    End If

    Range = Sheet.getCellRangeByName("O1:O6")
    Range.CellStyle = "MyTestStyle"
End sub

your crumpy code works for me with LO5.3.0.3 Linux, but anyway … I dit some clean up:

sub FormatRange()

   doc = ThisComponent
   Sheet = doc.CurrentController.ActiveSheet
   StyleFamilies = doc.StyleFamilies
   CellStyles = StyleFamilies.getByName("CellStyles")

   If not CellStyles.hasByName("MyTestStyle") Then
       NewStyle = Doc.createInstance("com.sun.star.style.CellStyle")
       CellStyles.insertByName("MyTestStyle", NewStyle)
    With NewStyle
        .ParentStyle = "Default"
        .CharWeight = com.sun.star.awt.FontWeight.BOLD
        .CharFontName = "Courier"
        .HoriJustify = 2        
        .CharHeight = 12
        .CellBackColor = RGB(255,141,56)
     End With
   End If

   Range = Sheet.getCellRangeByName("O1:O6")
   Range.CellStyle = "MyTestStyle"
End sub