简体   繁体   English

在LibreOffice上使用宏将图形错误导出为PNG

[英]Incorrect graph export as PNG using macros on LibreOffice

I am trying to export all charts on multiple sheet within my spreadsheet. 我正在尝试导出电子表格中多个工作表上的所有图表。 I've looked some examples online to came up with a code that extracts all graphs within my file as PNGs. 我在网上看了一些示例,想出了一个代码来提取文件中所有图形为PNG的代码。 But I may be missing something, because every time I run this macro, some images are generated misaligned (and not the same, sometimes images are correct). 但是我可能会丢失一些东西,因为每次运行此宏时,都会生成一些未对齐的图像(并且不相同,有时图像是正确的)。 This code is simple, but I don't what might be causing it. 这段代码很简单,但是我可能不是什么原因。 Could anyone help me solve this? 谁能帮我解决这个问题?

Sub ExportGraphs
    oDoc = ThisComponent

    Dim oSheet As Object
    Dim eSheets As Object

    Dim args(1) as new com.sun.star.beans.PropertyValue

    gef = CreateUnoService("com.sun.star.drawing.GraphicExportFilter")

    eSheets = oDoc.getSheets.createEnumeration()

    While eSheets.hasMoreElements
        oSheet = eSheets.nextElement()
        oDrawPage = oSheet.getDrawPage()
        iLimit = oDrawPage.getCount() -1

        For index = 0 to iLimit
            oDraw = oDrawPage.getByIndex(index)

            args(0).Name = "URL"
            args(0).Value = "file:///home/user_folder/Desktop/graphs/graph_" & oSheet.getName & "_" & index+1 & ".png"
            args(1).Name = "MimeType"
            args(1).Value = "image/png"

            gef.setSourceDocument(oDraw)
            gef.filter(args)

        Next
    Wend
End Sub

更改: MimeTypeMediaType在:

args(1).Name = "MimeType"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM