代码之家  ›  专栏  ›  技术社区  ›  John B. Walugembe

如何从Libreoffice Calc工作簿的所有工作表中删除所有图像

  •  2
  • John B. Walugembe  · 技术社区  · 8 年前

    Property or method not found: Pictures.

    Sub DeleteAllPics()
        Dim Pic As Object
        For Each Pic In ThisComponent.CurrentController.ActiveSheet.Pictures
           Pic.Delete
    Next Pic
    End Sub
    

    Object variable not set.

    Sub deleteAllPics()
        Dim wkSheet As Object
        For Each wkSheet In ThisWorkbook.ThisComponent.Sheets.getByName()
            Dim Pict As Object
            For Each Pict In wkSheet
                Pict.Delete
            Next Pict
        Next wkSheet       
    End Sub
    

    以下代码将删除Libreoffice Writer文档所有页面中的所有图片:

       Sub RemoveImages
           Dim oDoc as Object
           oDoc = ThisComponent
           Dim oGraphics as Object
           oGraphics = oDoc.getGraphicObjects()
           Dim oImg as Object
           For Each oImg in oGraphics
           oDoc.getText().removeTextContent(oImg)
           Next 
        End Sub
    

    我需要一个代码,将工作类似上述一个删除所有图像从所有工作表的计算工作簿。请帮帮我。

    1 回复  |  直到 7 年前
        1
  •  6
  •   Jim K    8 年前

    对于电子表格,您需要获得 XDrawPage 对于每张纸。

    For Each 对于每个 ,但为了保持一致 For 首选回路。)

    Sub DeleteAllPics()
        Dim oDoc As Object
        Dim oDrawPage As Object
        Dim oShape As Object
        Dim iShape As Integer
        Dim iSheet As Integer
        oDoc = ThisComponent
        For iSheet = 0 To oDoc.getSheets().getCount() - 1
            oDrawPage = oDoc.getSheets().getByIndex(iSheet).getDrawPage()
            For iShape = oDrawPage.getCount() - 1 To 0 Step -1
                oShape = oDrawPage.getByIndex(i)
                oDrawPage.remove(oShape)
            Next iShape
        Next iSheet
    End Sub