2

我使用 pyuno 完成了一个 python 脚本,它成功地将文档/xls/rtf 等转换为 pdf。然后我需要更新一个 mssql 数据库,因为 open office 目前支持 python 2.3,它很古老,缺乏对体面的数据库库的支持。所以我求助于使用 Jython,这样我就不会因为使用旧的 pyuno 在 OO python 环境中运行而感到负担。

这也意味着我的转换代码被破坏了,我现在需要使用 java 库而不是 pyuno 库。

导入 com.sun.star.beans.PropertyValue 作为 PropertyValue
导入 com.sun.star.bridge.XUnoUrlResolver 作为 XUnoUrlResolver
导入 com.sun.star.comp.helper.Bootstrap 作为 Bootstrap
->> 导入 com.sun.star.frame。 XComponentLoader as XComponentLoader
->> import com.sun.star.frame.XStorable as XStorable
import com.sun.star.lang.XMultiComponentFactory as XMultiComponentFactory
import com.sun.star.uno.UnoRuntime as UnoRuntime
import com.sun.star.uno .XComponentContext 作为 XComponentContext

带有“->>”的包含不导入编译器无法识别 com.sun.star.frame 看不到“框架”位。这些是我包含的库。

替代文字 http://www.freeimagehosting.net/uploads/eda5cda76d.jpg

关于这个问题的一些建议会很受欢迎

上下文 = XComponentContext
xMultiCompFactory = XMultiComponentFactory
xcomponentloader = XComponentLoader

//在python中使用
ctx = None
smgr = None
doc = None
url = None

context = Bootstrap.bootstrap()
xMultiCompFactory = self.context.getServiceManager()
xcomponentloader = UnoRuntime.queryInterface(XComponentLoader.class, ....xMultiCompFactory.createInstanceWithContext("com.sun.star.frame.Desktop", context))

file = "file:\\" + file
// 也相当于 url = uno.systemPathToFileUrl(file) 在 Java 中,这样我就可以利用它来很好地格式化我的路径
properties = []
p = PropertyValue()
p.Name = "Hidden"
p.Value = True
properties.append(p)
properties = tuple(properties)
doc = xcomponentloader.loadComponentFromURL(file, "_blank",0, properties)

4

2 回答 2

1

就这样,根据这个家伙的说法,你需要一些油......它就像一个魅力

http://www.oooforum.org/forum/viewtopic.phtml?p=304263#304263

包括这个库 C:\OpenOffice_24\program\classes\unoil.jar

于 2008-11-06T04:38:37.790 回答
0

Using Jython is a great idea for this I think. But why could you not use two scripts, one with pyuno/2.3 and one with pymssql/2.5 (or whatever db adapter you are using)?.

The intermediate format could be anything like a pickle, or json, or XML.

Edit: I should add that I have used pyuno quite extensively, and I feel your pain.

于 2008-11-05T11:09:58.247 回答