我需要从命令行运行 javascript 宏。我的 .js 脚本位于
open_office_location/share/Scripts/javascript/MultiplyCSV/multiplycsv.js
我发现了这个:
soffice.exe -headless "D:\test1.ODS" "macro://test1/Standard.Module1.Main"
如何识别脚本的模块名称? 我试过:
"macro://full path to .js file"
"macro://MultiplyCSV.multiplycsv.js"
"macro://MultiplyCSV/multiplycsv.js"
还有更多其他.. 我找不到解决方案。
抱歉我的英语不好。 你能帮助我吗?
最佳答案
最简单的方法是将其分配给“打开文档”事件。每当打开文档时,这将运行一个宏。为此,请转到 工具 -> 自定义 -> 事件
。更多信息请访问:https://wiki.openoffice.org/wiki/Documentation/OOoAuthors_User_Manual/Getting_Started/How_to_run_a_macro
如果您需要更大的灵 active ,您可以设置一个 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
关于javascript - 运行 share/scripts/javascript 命令行宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34363532/