import os from docx import Document # 创建新的空文档 merged_doc = Document() # 循环遍历所有.docx文件并将其合并到新文档中 for filename in os.listdir('.'): if filename.endswith('.docx'): doc = Document(filename) for element in doc.element.body: merged_doc.element.body.append(element) # 保存合并后的文档 merged_doc.save('merged.docx')
标签:docx,word,python,doc,filename,element,拼接,Document,merged From: https://www.cnblogs.com/dashenblog/p/17208164.html