python修改word文档的域_python修改word文件(doc)页眉页脚
发布日期:2021-11-19 18:35:43 浏览次数:8 分类:技术文章

本文共 510 字,大约阅读时间需要 1 分钟。

#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格式的文件不能转

转载地址:https://blog.csdn.net/weixin_39927214/article/details/110271797 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:torch 变量_[错误汇总]torch.load加载模型报错;cuda数据类型报错
下一篇:python数据库查询数据_Python数据库之数据操作

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月10日 07时18分07秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章