简体   繁体   English

何时导入uno

[英]When to import uno

Using Ubuntu 12.04 and LibreOffice 3.5.7.2. 使用Ubuntu 12.04和LibreOffice 3.5.7.2。

I am trying to understand Python scripting in Libre Office. 我正在尝试了解Libre Office中的Python脚本。 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. 我注意到有些示例导入了uno,有些则没有。 They all run fine, but if I comment out import uno, that script stops working. 它们都运行良好,但是如果我取消注释import uno,该脚本将停止工作。

Could someone explain to me when uno needs to be imported. 有人可以向我解释何时需要导入uno。

Thanks, Jim 谢谢,吉姆

Try just importing uno. 尝试仅导入uno。 At the very most it will slow your program by 2 seconds. 最多最多会使您的程序慢2秒。

import uno ##JUST DO It!

What examples have you looked? 您看过哪些例子?

UNO is required when you need an UNO context. 当您需要UNO上下文时,需要UNO。 This allows you to connect on LO or OOo. 这使您可以在LO或OOo上进行连接。

Here is a small example when you need to use UNO. 这是您需要使用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" )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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