【问题标题】:How do we import the listener events of LibreOffice Writer in Visual Basic 6我们如何在 Visual Basic 6 中导入 LibreOffice Writer 的监听器事件
【发布时间】:2017-10-31 14:25:35
【问题描述】:

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

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

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

我收到一个错误

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

有人可以帮忙吗?

【问题讨论】:

    标签: vb6 libreoffice libreoffice-basic


    【解决方案1】:

    正如here 解释的那样,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的信息也可能会有所帮助。

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

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

    【讨论】:

    • 感谢您的快速回复。我仍然需要一个使用监听器接口实现监听器的示例,并附上解释,因为我是 UNO 技术的新手。
    • 您很可能找不到任何 VB6 的好示例,因此我建议您使用更流行的语言,因为您没有经验。我可以轻松地提供 Python、LO Basic 或 Java 的示例。 Javascript、C++ 和 C# 也是可能的。
    • 到目前为止,我还没有一个例子。你能建议任何其他方法来澄清吗?在我的工作中,我真的需要这些信息。
    • @JimK 我有兴趣有一个 XPropertyChangeListener 的 Java 示例...
    • @JohnRDORazio 你应该问一个新问题。但是,Java 中已经有几个示例,例如api.libreoffice.org/examples/DevelopersGuide/OfficeDev/…。谷歌“java xpropertychangelistener libreoffice”。
    猜你喜欢
    • 2017-10-17
    • 1970-01-01
    • 2021-01-19
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多