from  docx import  Document
w=Document()
#添加页眉页脚
页眉=w.sections[0].header
段落=页眉.paragraphs[0].add_run('这是第一节页眉')
页脚=w.sections[0].footer
段落=页脚.paragraphs[0].add_run('这是一个节页脚')


#添加新页眉页脚(设置新的节)
w.add_section()
页眉_2=w.sections[1].header
页眉_2.is_linked_to_previous=False   #不使用上个节的内容和样式
页眉_a=w.sections[1].header
paragraph=页眉_a.paragraphs[0].add_run('这是第二个节的页眉')

w.save(r'E:\word练习\页眉页脚_5.docx')

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。