When to import uno

假装没事ソ 提交于 2020-01-04 13:22:48

问题


Using Ubuntu 12.04 and LibreOffice 3.5.7.2.

I am trying to understand Python scripting in Libre Office. I've read quite a bit on the web and looked at and run some examples. I noticed that some examples import uno and some don't. They all run fine, but if I comment out import uno, that script stops working.

Could someone explain to me when uno needs to be imported.

Thanks, Jim


回答1:


Try just importing uno. At the very most it will slow your program by 2 seconds.

import uno ##JUST DO It!



回答2:


What examples have you looked?

UNO is required when you need an UNO context. This allows you to connect on LO or OOo.

Here is a small example when you need to use UNO.

import uno

# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()

# create the UnoUrlResolver
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext )

ctx = resolver.resolve( "uno:pipe,name=addtemppipe;urp;StarOffice.ComponentContext" )


来源:https://stackoverflow.com/questions/17516589/when-to-import-uno

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