LibreOffice 中的宏,用于将 Impress Slide 的背景更改为纯黑色

Macro in LibreOffice to change the background of an Impress Slide to a solid black color

找了一圈也没找到。需要一个宏,以便我可以在我拥有的 695 个不同文件上重复 695 次。文档有点不安,还是我运气不好

我可以在 Microsoft VBA 中按如下方式完成:

Sub VbaBlackies
    Dim oSl As Slide
    For Each oSl In ActivePresentation.Slides
        With oSl
            .FollowMasterBackground = msoFalse
            .DisplayMasterShapes = msoFalse
            With .background
                .Fill.ForeColor.RGB = RGB(0, 0, 0)
                .Fill.BackColor.RGB = RGB(0, 0, 0)
                End With
            End With
        Next oSl
End Sub

我正在 LibreOffice BASIC 中寻找类似的东西。我可以这样开始编写代码:

Sub Main
Dim oDoc As Object
Dim oDPages As Object
Dim oDPage As Object
oDoc= ThisComponent
oDPages = oDoc.getDrawPAges()
For i=0 To oDPages.count()-1
    oDPage = oDPages.getByIndex(i)
    oDPage.Background = RGB(0,0,0)  'This does not work.
    'I have no idea on how to access the object's properties and alter them.
    Next i
End Sub

有什么想法吗?

你要找的是 Andrew Pitonyak's macro document 的清单 15.1,这是宏编程的重要参考。

Sub ChangeBackground
    Dim oDoc as Object
    oDoc = ThisComponent
    Dim oDrawPages as Object, oDrawPage as Object
    oDrawPages = oDoc.getDrawPages()
    oDrawPage = oDrawPages.getByIndex(0)
    Dim oBackground as Object
    oBackground = oDoc.createInstance("com.sun.star.drawing.Background")
    oBackground.FillColor = RGB(250,0,0)
    oDrawPage.Background = oBackground
End Sub

API 文档位于 https://www.openoffice.org/api/docs/common/ref/com/sun/star/drawing/Background.html

是的!工作得很好,非常感谢您的回答!

这是对我有用的最终代码:

Sub Main
Dim oDoc As Object
Dim oDPages As Object
Dim oDPage As Object

oDoc = ThisComponent
oDPages = oDoc.getDrawPAges()

For i=0 To oDPages.count()-1
    oDPage = oDPages.getByIndex(i)
    Dim oBackground As Object
    oBackground = oDoc.createInstance("com.sun.star.drawing.Background")
    oBackground.FillColor = RGB(0,0,0)
    oDPage.Background = oBackground
    Next i
End Sub