我使用 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 = Nonecontext = 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)