2016-08-23 534 views
0

打开Word文档时,当试图打开一个.dot文件,python-docx,我得到的错误:型无关系与Python

KeyError: "no relationship of type 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' in collection" 

这是有问题的代码:

from docx import Document 
document = Document('file.dot') 

这里的实际问题是什么?

回答

2

您是如何生成输入文件的? Here这是一个关于将文件保存为严格打开XML文档时的类型的问题。试试标准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 
+0

我加在回答OPC-诊断链接。这是一个用于探索和诊断Microsoft Office Open XML文件问题的小工具。 –

+0

你可以给我们一个坏文件的链接吗? –

+0

我添加了一个修复的想法,你可以测试它吗? –