使用 Python 打开 Word 文档时没有类型关系
No relationship of type when opening Word document with Python
尝试使用 python-docx
打开 .dot
文件时出现错误:
KeyError: "no relationship of type 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' in collection"
这是有问题的代码:
from docx import Document
document = Document('file.dot')
这里的实际问题是什么?
你是如何生成输入文件的? Here 当您将文件另存为 Strict Open XML Document 时,类型有问题。试试标准的 Word 文档。
您可以使用 opc-diag:
获取有关文件内部关系的更多信息
opc browse <FILE> .rels
尝试修复错误文件的想法:
# Extract the bad file to a temporary folder
unzip <FILE> -d bad-file
# Repackage the extracted data to a new fresh file
opc repackage bad-file new-file.docx
# A diff of relationships
opc diff-item test.docx test-ok.docx .rels
尝试使用 python-docx
打开 .dot
文件时出现错误:
KeyError: "no relationship of type 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' in collection"
这是有问题的代码:
from docx import Document
document = Document('file.dot')
这里的实际问题是什么?
你是如何生成输入文件的? Here 当您将文件另存为 Strict Open XML Document 时,类型有问题。试试标准的 Word 文档。
您可以使用 opc-diag:
获取有关文件内部关系的更多信息opc browse <FILE> .rels
尝试修复错误文件的想法:
# Extract the bad file to a temporary folder
unzip <FILE> -d bad-file
# Repackage the extracted data to a new fresh file
opc repackage bad-file new-file.docx
# A diff of relationships
opc diff-item test.docx test-ok.docx .rels