openoffice-calc - 如何从另一个文档运行脚本
问题描述
我有两个文档 LibreOffice calc test1.ods 和 test2.ods。我想从 test1 的脚本在 test2 中运行一个脚本。
- 当 test2 由 test1 的脚本打开时,即使从 test2 也无法在 test2 上运行脚本。我如何才能通过 test2 doc 的安全性?
- 如何从 test1 上的脚本自动运行 test2 上的脚本?
REM ***** BASIC *****
'Script on Test1
Sub Main
Dim urlDest As String
Dim PropFich(1) As New com.sun.star.beans.PropertyValue
Dim oDocDest As Object
PropFich(0).Name = "MacroExecutionMode"
PropFich(0).value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE
urlDest = ConvertToUrl("/home/patrick/Bureau/Test/test2.ods")
oDocDest = StarDesktop.loadComponentFromUrl(urlDest, "_blank", 0, PropFich())
' ...
'run oDocDest.Standard.Module1.Main() ???
End Sub
解决方案
获取另一个文档的脚本提供程序并使用它来调用宏。
oScriptProvider = oDocDest.getScriptProvider()
oScript = oScriptProvider.getScript(_
"vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document")
result = oScript.invoke(Array(), Array(), Array())
为此,您需要通过转到Tools > Options > Security来允许运行宏。
推荐阅读
- c - 如何在没有警告的情况下使结构中的变量等于任何值?(C)
- sql - 选择没有任何评级的所有书籍的标题
- javascript - 如何在 Safari 中将 onPaste 优先于 onKeyPress
- sas - 在 sas 中一次将文本附加到所有列
- django - 过滤外键查询集
- powershell - 从 Powershell 中提取 Info AD 属性
- java - 如何忽略像“car”这样的空 json 对象:{},这会在使用 jackson 反序列化后导致空 pojos
- python - 在 pandas 数据框中获取 t-1 值(来自上一个单元格)
- flutter - showGeneralDialog 中的 barrierDismissible 不适用于 Scaffold
- ibm-mq - 如何将两个文件发送到具有不同 MsgSeqNumber 的单个 MQ 消息中