在liboffice宏中打开XLSX



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

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

Target = "C:UsersRKerriganDocumentsScriptsMailerreportgeneratorMiller 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.

所以然后我搜索了一下,从stackoverflow: https://stackoverflow.com/a/65201568/16953756找到了这个链接下面是这个例子: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:UsersRKerriganDocumentsScriptsMailerreportgeneratorMiller Radiology Mailers Template.xlsx"

我认为它是引号,所以我尝试了双斜杠,但也不起作用。

请尝试

Sub OpenRadiologyMailers()
Dim sFilename As String 
Dim oSourceSpreadsheet As Variant 
sFilename = ConvertToURL("C:UsersRKerriganDocumentsScriptsMailerreportgeneratorMiller 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 

最新更新