问题
When trying to open a .dot
file with python-docx
, I am getting the error:
KeyError: "no relationship of type 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' in collection"
This is the code in question:
from docx import Document
document = Document('file.dot')
What is the actual problem here?
回答1:
How did you generate the input file? Here it is an issue about the type when you save the file as Strict Open XML Document. Try the standard Word document.
You can get more informations about relations inside the file using opc-diag:
opc browse <FILE> .rels
An idea to try to fix the bad file:
# 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
来源:https://stackoverflow.com/questions/39104325/no-relationship-of-type-when-opening-word-document-with-python