2

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

Agent_15x
  • 373
  • 4
  • 13
  • You need UNO to talk to office from Python. On Mac that's not difficult because office bundles with a functioning Python interpreter and you can just `import uno` and connect to a running office server. On Linux things are more difficult, see this thread: http://stackoverflow.com/questions/24965406/getting-python-to-import-uno-pyuno – Jens Oct 09 '14 at 11:28

2 Answers2

0

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

import uno ##JUST DO It!
JD3
  • 410
  • 1
  • 5
  • 14
0

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