2

我们如何在 Visual Basic 6 中导入 LibreOffice writer 的侦听器事件?

我正在尝试创建一个 UNO 服务来获取容器侦听器事件,如下面的代码,

Dim oListener As Object
oListener = CreateUnoListener("ContListener_", 
    "com.sun.star.container.XContainerListener")

我收到一个错误

编译错误:未定义子或函数

有人可以帮忙吗?

4

1 回答 1

1

正如这里所解释的,CreateUnoListener在 VB6 中不起作用。因此,有必要以不同的方式实现侦听器接口。

这是来自https://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Document_Events的 VBScript 示例。

set xContext = objServiceManager.getPropertyValue( "DefaultContext" )
set xCoreReflection = xContext.getValueByName( "/singletons/com.sun.star.reflection.theCoreReflection" )
set xClass = xCoreReflection.forName( "com.sun.star.document.XEventBroadcaster" )
set xMethod = xClass.getMethod( "addEventListener" )

dim invokeargs(0)
invokeargs(0) = myListener

set value = objServiceManager.Bridge_GetValueObject()
call value.InitInOutParam("[]any", invokeargs)
call xMethod.invoke( objDocument, value )

定义一个名为myListener.

查看https://www.openoffice.org/udk/common/man/tutorial/office_automation.html上的信息也可能会有所帮助。

尽管最终解决方案使用 Javascript,但在https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=14217讨论了有人尝试类似代码。

免责声明:我没有任何方法来测试 VB6 代码,因此这些信息可能并不完全准确。如果您切换到 Python 或 LibreOffice 常用的其他语言,那么我可以提供更多帮助。

于 2017-10-31T15:55:10.343 回答