我需要从命令行运行javascript宏。我的.js脚本位于
open_office_location /共享/脚本/ JavaScript的/ MultiplyCSV / multiplycsv.js
我发现了这个:
soffice.exe -headless“D:\ test1.ODS”“macro://test1/Standard.Module1.Main”
如何识别脚本的模块名称? 我试过了:
“macro:// .js文件的完整路径”
“宏://MultiplyCSV.multiplycsv.js”
“宏://MultiplyCSV/multiplycsv.js”
以及更多其他.. 我找不到解决方案。
抱歉我的英语不好。 你能帮助我吗?
答案 0 :(得分:1)
最简单的方法是将其分配给“Open Document”事件。每当打开文档时,这将运行宏。为此,请转到Tools -> Customized -> Events
。更多信息请访问:https://wiki.openoffice.org/wiki/Documentation/OOoAuthors_User_Manual/Getting_Started/How_to_run_a_macro
如果您需要更多灵活性,可以设置一个Basic函数来调用Javascript代码。然后使用macro://
语法。为此,首先将此基本功能添加到Module1,改编自authoritative Andrew Pitonyak document:
Sub CallMultiplyCSV
Dim oDisp
Dim sMacroURL As String
Dim sMacroName As String
Dim sMacroLocation As String
Dim oFrame
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
REM To figure out the URL, add a button and then set the button
REM to call a macro.
sMacroName = "vnd.sun.star.script:MultiplyCSV.multiplycsv.js"
sMacroLocation = "?language=JavaScript&location=share"
sMacroURL = sMacroName & sMacroLocation
REM I want to call a macro contained in ThisComponent, so I
REM must use the frame from the document containing the macro
REM as the dispatch recipient.
oFrame = ThisComponent.CurrentController.Frame
oDisp.executeDispatch(oFrame, sMacroURL, "", 0, Array())
'oDisp.executeDispatch(StarDesktop, sMacroURL, "", 0, Array())
End Sub
然后调用此基本功能:
soffice.exe -headless "D:\test1.ODS" "macro://test1/Standard.Module1.CallMultiplyCSV"
有关sMacroName
和sMacroLocation
的详细信息,请参阅:https://wiki.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework_URI_Specification