如何使用 VBA 在 LibreOffice Calc 中自动生成颜色样式?

如何使用 VBA 在 LibreOffice Calc 中自动生成颜色样式?

我希望能够运行一个宏来自动创建一组改变单元格背景颜色的命名样式。

我尝试了这个,但是没有用:

REM  *****  BASIC  *****

Sub CreateColorStyles()
    Dim oDoc As Object
    Dim oCellStyles As Object
    Dim r As Integer, g As Integer, b As Integer
    Dim sName As String
    Dim sVBA As String

    oDoc = ThisComponent
    oCellStyles = oDoc.StyleFamilies.getByName("CellStyles")
    'oStyle = oDoc.createInstance("com.sun.star.style.CellStyle")
    
    For r = 0 To 255
        For g = 0 To 255
            For b = 0 To 255
                sName =  r & "-" & g & "-" & b
                sVBA = "oRGB-" & sName & " = oDoc.createInstance(" & """" & "com.sun.star.style.CellStyle" & """" & ")"
                oStyle = oDoc.createInstance("com.sun.star.style.CellStyle")
                oStyle.Name = "oRGB-" & sName
                oStyle.CellBackColor = RGB(r, g, b)
                oCellStyles.insertByName(oStyle.Name, oStyle)
            Next b
        Next g
    Next r
    
End Sub

相关内容