#coding=utf8
import os
import docx
nowpath='需要修改的文件的路径'
topath='另存到的路径'
os.chdir(nowpath)
for iin os.listdir('.'):
print(i)
if os.path.splitext(i)[1]== '.doc':
try:
file=docx.Document(i)
file.sections[0].header.paragraphs[0].text= '你要修改成的页眉'
file.sections[0].footer.paragraphs[0].text= '你要修改成的页脚'
file.save(os.path.join(topath,i))
except Exception as e:
print(e)
continue
遇见的错误:
file 'xxxx.doc' is not a Word file, content type is 'application/vnd.openxmlformats-officedocument.themeManager+xml'
不是word格式的文件不能转