How to get the opened document using UNO?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 05:26:48

Use this in your code to get the current document:

import com.sun.star.frame.XDesktop;
...
XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, oDesktop);
XComponent xComponent = xDesktop.getCurrentComponent();

I opened the BookmarkInsertion sample in NetBeans and added this code to use the current document instead of loading a new document.

As far as the error, there may be a problem with how it is getting built. A couple of things to check:

  • Does the Office SDK version match the Office version? Check version number and whether it's 32- or 64-bit.
  • Make sure that 4 .jar files (juh.jar, jurt.jar, unoil.jar, ridl.jar) are shown under Libraries in NetBeans, because they need to be included along with the add-on.

If you get frustrated with trying to get the build set up correctly, then you might find it easier to use python, since it doesn't need to be compiled. Also python does not require queryInterface().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!