Python-uno包在安装了python2.6和python2.7时的问题

1 投票
3 回答
1344 浏览
提问于 2025-04-17 02:54

我正在使用OpenERP和一个叫做report_openoffice的模块。这个模块需要安装一个叫做python-uno的包。问题是我有两个版本的Python(2.6和2.7)。当我安装这个包时,Python 2.7可以使用python-uno这个包,但Python 2.6却不能。我需要在Python 2.6中使用它。有没有办法为Python 2.6安装这个包?

附注:我使用的是Ubuntu 11.04

非常感谢

3 个回答

-1

在Python 2.7中安装uno这个包,然后运行下面的命令:

sudo apt-get install libreoffice python-genshi python-cairo python-lxml python-setuptools
sudo apt-get install libreoffice-script-provider-python

easy_install uno
1

python-uno 通常用来操作 OpenOffice 或 LibreOffice。不过,如果你只是想创建 odt 或 pdf 格式的报告,可以使用 PyQt4。

下面是一个简单的例子,展示如何写入一个 odt 文件:

>>>from pyqt4 import QtGui
# Create a document object
>>>doc = QtGui.QTextDocument()
# Create a cursor pointing to the beginning of the document
>>>cursor = QtGui.QTextCursor(doc)
# Insert some text
>>>cursor.insertText('Hello world')
# Create a writer to save the document
>>>writer = QtGui.QTextDocumentWriter()
>>>writer.supportedDocumentFormats()
[PyQt4.QtCore.QByteArray(b'HTML'), PyQt4.QtCore.QByteArray(b'ODF'), PyQt4.QtCore.QByteArray(b'plaintext')]
>>>odf_format = writer.supportedDocumentFormats()[1]
>>>writer.setFormat(odf_format)
>>>writer.setFileName('hello_world.odt')
>>>writer.write(doc) # Return True if successful
True

QTextCursor 还可以插入表格、框架、块和图片。想了解更多信息,可以查看这里: http://qt-project.org/doc/qt-4.8/qtextcursor.html

2

我把2.7版本的uno.pyunohelper.py做了软链接到2.6版本,这样看起来是可以用的。作为管理员,你可以这样做(或者用sudo命令):

$> cd /usr/lib/python2.6/dist-packages
$> ln -s /usr/lib/python2.7/dist-packages/uno.py
$> ln -s /usr/lib/python2.7/dist-packages/unohelper.py

撰写回答