我需要从命令行运行javascript宏。我的.js脚本位于
open_office_location / share / Scripts / javascript / MultiplyCSV / multiplycsv.js
我找到了这个:
soffice.exe-无头“ D:\ test1.ODS”“宏://test1/Standard.Module1.Main”
如何识别脚本的模块名称?
我试过了:
“ macro://.js文件的完整路径”
“ macro://MultiplyCSV.multiplycsv.js”
“ macro://MultiplyCSV/multiplycsv.js”
还有更多..
我找不到解决方法。
对不起,我的英语不好。
你能帮助我吗?
最佳答案
最简单的方法是将其分配给“打开文档”事件。每当打开文档时,它将运行一个宏。为此,请转到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