提供处理OpenXML文档的资源。
openxmllib-py3的Python项目详细描述
openxmllib-py3
这是[openxmllib](https://github.com/glenfant/openxmllib)的分支 有Python的支持。在
openxmllib是一组处理新ecma376office文件的工具 称为OpenXML的格式。在
http://www.ecma-international.org/publications/standards/Ecma-376.htm
OpenXML格式由Microsoft Office 2007和更高版本使用。苹果iWork 从iWork'08开始,OpenOffice也有使用这种格式的过滤器 和OO版本2.2。在
特点
测试特征
- 从文档中提取单词用于索引。在
- 从文档获取元数据
- 将OpenXml mimetypes添加到标准mimetypes模块中。在
- 如果文档包含封面缩略图图像,请将其提取出来
计划功能
- 将文档转换为HTML
公共API
这些例子说明了:
>>> import openxmllib >>> doc = openxmllib.openXmlDocument(path='office.docx') >>> # Raises a ValueError on not supported office files. >>> doc.mimeType 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' >>> doc.coreProperties # Keys may depend on application {'title': u'blah...', u'creator': u'John Doe', ...} >>> doc.extendedProperties # Keys may depend on application {'Words': u'312', 'Application': u'Your favorite word processor', ...} >>> doc.customProperties # May return an empty mapping {'My property': u'My value', ...} >>> doc.allProperties # Merges core+extended+custom properties (see above) {...} >>> doc.indexableText(include_properties=False) u'all the words of that document body' >>> doc.indexableText(include_properties=True) u'all the words of that document body and all properties values' >>> doc.documentCover() ('jpg', <open file '/var/folders/.../docProps/thumbnail.jpeg', mode 'rb' at 0x1af300>)
标准mimetypes包扩展
^{pr2}$文件工厂签名:
>>> # We have the path for the office file >>> doc = openxmllib.openXmlDocument(path='office.docx') >>> # We have a file object for the office file >>> fh = open('office.docx', 'rb') >>> doc = openxmllib.openXmlDocument(file_='office.docx') >>> # We have the URL for the office file >>> doc = openxmllib.openXmlDocument(url='http://domain.tld/office.docx') >>> # Xe have the raw data of the office file >>> import mimetypes >>> docx_mimetype = mimetypes.guess_type('office.docx') >>> body = open('office.docx', 'rb').read() >>> doc = open(data=body, mime_type=docx_mimetype)
请注意,如果您没有运行Python应用程序,您可能会得到索引 包含的文档中的文本openxmlinfo.py控制台实用程序。只需输入:
$ openxmlinfo --help
复制和许可
版权所有(c)2008 Gilles Lenfant
本软件受GNU公众条款的约束 许可证,2.0版(GPL)。应随附GPL副本 分配。此软件按“原样”提供 明示或默示的保证被否认,包括但不 仅限于对所有权、适销性的默示保证, 反对侵权,以及对特定目的的适用性
有关此包中包含的COPYING文件的更多详细信息。在
状态
从2.0版开始,这个包在Linux上使用Python3.8.x进行测试。 如果可以满足依赖关系,那么它很可能也适用于其他环境。在
安装
使用常用的setuptools命令:
$ pip install openxmllib-py3
注意,这将安装优秀的lxml鸡蛋,如果还没有完成。在
从现在起,您可以在Python应用程序中“导入openxmllib”并使用 “openxmlinfo”命令行实用程序。在
Gotchas
请注意,大多数文本数据都来自各种openxmllib 服务可以是us ascii或Unicode。这是lxml的副作用 (bug还是功能?)。转换这些文本取决于您的应用程序 到适当的字符集。在
实际上,我们并不处理由于XML格式错误或 意外的结构。你应该处理各种(潜在的) 应用程序中try(…)except(…)块中的问题。在
开发和测试
您应该从位于https://github.com/wilbertom/openxmllib-py3的存储库中获取openxmllib。在
然后:
$ cd /where/you/installed/openxmllib $ python setup.py develop
请注意,测试不需要安装:
$ cd tests $ python runalltests.py
支持
使用project site提供的问题跟踪器。在
学分
- 吉勒·伦芬特[吉尔斯·伦芬特]<;gilles dot lenfant在gmail.com>
- 凯文·德尔迪克[凯文·德尔迪克]<;kevin在deldycke dot com>
- 雨果·洛佩斯·塔瓦雷斯[hltbra]<;hltbra at gmail dot com>
- Petri Savolainen[Petri]<;Petri dot Savolainen at koodaamo dot fi>
- 埃里克·沃恩利希[ewohnlich]<;https://github.com/ewohnlich>
- 威尔伯托•莫拉莱斯【威尔伯托姆】<;https://github.com/wilbertom/>
未来特性和错误修复
特点
删除下载的临时文件
当数据来自HTTP(…)URL时,它存储在一个临时文件中 处理后未删除。在
支持标准mimetypes模块
将我们的mime类型添加到标准Python模块中。在
人类可读的纯文本转换
>>> fromopenxmllibimportopenXmlDocument>>> doc=openXmlDocument(...)>>> doc.textDocument(target_directory)
(吨)他的电子表格可能不可用)
HTML转换
{pr 9}$这需要找到开源的XSLT样式表。在
文档生成
我想说的更多
错误修复
等待反馈;o)历史
1.1.1
{bq 1}$1.1
{bq 2}$1.0.7
{bq 3}$1.0.6
{bq 4}$1.0.5
{bq 5}$1.0.4
{bq 6}$1.0.3
{7磅}$1.0.2
{bq 8}$1.0.1
{bq 9}$1.0.0
{bq 10}$- 项目
标签: