简体   繁体   中英

When to import uno

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

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

import uno ##JUST DO It!

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" )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM