使用jython和openoffice2.4将文档转换为pd

2024-06-02 06:59:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我用pyuno完成了一个python脚本,它成功地将文档/xls/rtf等转换为pdf。 然后我需要更新一个mssql数据库,因为openoffice目前支持python2.3,它很古老,缺少对像样的数据库libs的支持。所以我求助于使用Jython,这样我就不会因为在oopython环境中使用旧pyuno运行而负担过重。在

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

import com.sun.star.beans.PropertyValue as PropertyValue
import com.sun.star.bridge.XUnoUrlResolver as XUnoUrlResolver
import com.sun.star.comp.helper.Bootstrap as Bootstrap
->> import 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 as XComponentContext

带“->;”的include不导入编译器无法识别太阳之星.frame看不到“frame”位。这些是我包括的LIB。在

alt text http://www.freeimagehosting.net/uploads/eda5cda76d.jpg

关于这件事的一些建议会很受欢迎的

context = XComponentContext
xMultiCompFactory = XMultiComponentFactory
xcomponentloader = XComponentLoader

//used in 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
// also what is the equivalent of url = uno.systemPathToFileUrl(file) in Java so that I can make use of it to nicely format my path
properties = []
p = PropertyValue()
p.Name = "Hidden"
p.Value = True
properties.append(p)
properties = tuple(properties)
doc = xcomponentloader.loadComponentFromURL(file, "_blank",0, properties)


Tags: importcomnoneascontextpropertiesbootstrapframe
2条回答

根据这个人的说法,你需要一些油。。。。它就像一个符咒

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

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

我认为使用Jython是一个很好的主意。但是为什么不能使用两个脚本,一个用于pyuno/2.3,一个用于pymssql/2.5(或者您正在使用的任何数据库适配器)?。在

中间格式可以是pickle、json或XML。在

编辑:我应该补充一点,我已经非常广泛地使用了pyuno,我感觉到了你的痛苦。在

相关问题 更多 >