2016-08-23 537 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

我添加了一個修復的想法,你可以測試它嗎? –