【发布时间】:2014-09-15 05:26:11
【问题描述】:
我已经使用 zipfile 使用 ElementTree 包成功读取了 .docx 文件。但我意识到没有档案 'word/document.xml'for .doc files 。我查看了文档,但没有找到任何文档。怎么读?
对于 docx,我使用了:
import zipfile as zf
import xml.etree.ElementTree as ET
z = zf.ZipFile("test.docx")
doc_xml = z.open('word/document.xml')
tree = ET.parse(doc_xml)
对 .doc 使用上述内容:
KeyError: "There is no item named 'word/document.xml' in the archive"
我在 ElementTree 文档中看到了一些可供阅读的内容,但这仅适用于 xml 文件。
doc_xml = open('yesblue.doc','r')
这个应该怎么做?可能类似于在 python 本身中将.doc 转换为.docx。
编辑:.doc 格式以二进制形式存储数据,不能使用 XML。
【问题讨论】:
标签: xml python-2.7 docx elementtree doc