问题
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