pip install python-docx #第一步先安装python-docx模块
import docx def replace_text_in_word_document(file_path, old_text, new_text): doc = docx.Document(file_path) for para in doc.paragraphs: para.text = para.text.replace(old_text, new_text) doc.save(file_path) replace_text_in_word_document("document.docx", "old_text", "new_text") #以上为代码
标签:docx,word,python,text,replace,文档,old From: https://www.cnblogs.com/dashenblog/p/17091111.html