【问题标题】:Macro in LibreOffice to change the background of an Impress Slide to a solid black colorLibreOffice 中的宏,用于将 Impress Slide 的背景更改为纯黑色
【发布时间】:2017-07-18 15:36:12
【问题描述】:

环顾四周,没有找到。需要一个宏,以便我可以在我拥有的 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

有什么想法吗?

【问题讨论】:

  • 记录手动更改的宏。这可能会给你你需要的代码。
  • 试过了,但是 Impress 不记录宏。
  • 录制了一个宏在Calc中执行类似的操作,改变了单元格的背景颜色。给了我一些提示,但在获取 Slide 对象的“框架”引用时遇到了麻烦。

标签: vba libreoffice libreoffice-impress


【解决方案1】:

您正在寻找的内容在 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

【讨论】:

    【解决方案2】:

    是的!像魅力一样工作,非常感谢您的回答!

    这是为我解决的最终代码:

    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
    

    【讨论】:

      猜你喜欢
      • 2020-04-03
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 2015-05-30
      • 2022-11-27
      • 2013-04-20
      • 2011-02-12
      • 1970-01-01
      相关资源
      最近更新 更多