javascript - 运行 share/scripts/javascript 命令行宏

标签 javascript macros openoffice.org

我需要从命令行运行 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"

有关 sMacroNamesMacroLocation 的详细信息,请参阅:https://wiki.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework_URI_Specification

关于javascript - 运行 share/scripts/javascript 命令行宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34363532/

相关文章:

c# - Visual Studio 2012 - 如何自动打开关闭花括号?

c++ - 使用 C++ 宏从嵌套括号中提取项目

openoffice.org - LibreOffice writer 命令行转换 PDF 但需要横向选项

svn - 我应该如何在 OpenOffice 中保存文件,使其在 Subversion 中不是二进制文件?

Java、OpenOffice、创建获取文档作为 jsp 响应作为 pdf

javascript - 为什么 getElementById() 在 Elements 上不可用?

javascript 将回车符添加到字符串以提高可读性

javascript - 具有自动填充的图像网格

c - c中typedef和#define一样吗?

javascript - 为什么正向lookbehinds被捕获作为javascript中正则表达式匹配的一部分?