在 libreoffice 宏中打开 xlsx

open xlsx in libreoffice macro

我试图从 libreoffice calc 的宏中打开一个 excel 文件,但我不断遇到错误。这是我第一次使用 libreoffice 宏。

这是我的第一次尝试,来自一个网站,有人问了同样的问题,所以我在那里尝试了代码:https://forum.openoffice.org/en/forum/viewtopic.php?f=5&t=17075

Target = "C:\Users\RKerrigan\Documents\Scripts\Mailerreportgenerator\Miller Radiology Mailers Template.xlsx"
    TargetURL = convertToURL(Target)
    Empty() = Array()
    TestDoc = StarDesktop.loadComponentFromURL(TargetURL, "_blank", 0, Empty())

但我得到的错误是关于第 6 行 (Empty() = Array()):

BASIC runtime error.
'382'
This property is read-only.

然后我四处搜索并从 Whosebug 中找到了这个 link: 这让你想到这个例子:https://help.libreoffice.org/6.4/en-US/text/sbasic/shared/stardesktop.html

Dim docURL As String
Dim doc As Object, docProperties()
docURL = ConvertToURL("C:\Users\RKerrigan\Documents\Scripts\Mailerreportgenerator\Miller Radiology Mailers Template.xlsx")
Rem com.sun.star.frame.Desktop
doc = StarDesktop.LoadComponentFromURL(docURL, "_blank", 0, docProperties)

但我收到另一个错误提示:

BASIC runtime error.
'1'

Type: com.sun.star.lang.IllegalArgumentException
Message: Unsupported URL <file:///C://Users//RKerrigan//Documents//Scripts//Mailerreportgenerator//Miller%20Radiology%20Mailers%20Template.xlsx>: "type detection failed"

谁能帮我用 libreoffice 宏打开这个文件? "C:\Users\RKerrigan\Documents\Scripts\Mailerreportgenerator\Miller Radiology Mailers Template.xlsx"

我认为这是引号,所以我尝试了双斜线,但也没有用。

请尝试

    Sub OpenRadiologyMailers()
    Dim sFilename As String 
    Dim oSourceSpreadsheet As Variant 
        sFilename = ConvertToURL("C:\Users\RKerrigan\Documents\Scripts\Mailerreportgenerator\Miller Radiology Mailers Template.xlsx")
        If Not FileExists(sFilename) Then 
            MsgBox("File not found!")
            Exit Sub 
        EndIf 
        
        GlobalScope.BasicLibraries.loadLibrary("Tools")
        oSourceSpreadsheet = OpenDocument(sFilename, Array())
        If IsEmpty(oSourceSpreadsheet) Then 
            MsgBox("The file may be open in another application",0,"Failed to load file")
            Exit Sub 
        EndIf 
    '       ... further actions with the document oSourceSpreadsheet
    End Sub