-1
我正在使用python-docx模塊對大量文檔進行一些編輯。它們都包含一個標題,我需要替換一個數字,但每次我這樣做時,文檔都不會打開,並顯示內容無法讀取的錯誤。任何人有任何想法,爲什麼發生這種情況,或示例工作代碼片段?謝謝。搜索和替換不工作在標題? Python docx
from docx import *
#document = yourdocument.docx
filename = "NUR-ADM-2001"
relationships = relationshiplist()
document = opendocx("C:/Users/ai/My Documents/Nursing docs/" + filename + ".docx")
docbody = document.xpath('/w:document/w:body',namespaces=nsprefixes)[0]
advReplace(docbody, "NUR-NPM 101", "NUR-NPM 202")
# Create our properties, contenttypes, and other support files
coreprops = coreproperties(title='Nursing Doc',subject='Policies',creator='IA',keywords='Policy'])
appprops = appproperties()
contenttypes = contenttypes()
websettings = websettings()
wordrelationships = wordrelationships(relationships)
# Save our document
savedocx(document,coreprops,appprops,contenttypes,websettings, wordrelationships,"C:/Users/ai/My Documents/Nursing docs/" + filename + ".docx")
編輯:所以它最終可以打開文檔,但它說一些內容無法顯示,並且頭文件已經消失......想法?
發佈一些示例代碼,以便我們可以更好地爲您提供幫助。你說每次我做「這個」...你怎麼做到這一點? – Lanaru 2012-07-25 20:29:14
這樣更好,現在什麼是錯誤的完整追溯? – 2012-07-25 20:47:32
這是奇怪的事情......它沒有追蹤,它運行良好。當我到目錄檢查示例文檔時,它不會打開文檔! – Ishu108 2012-07-25 20:51:35