页眉页脚的设置

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')
原文地址:https://www.cnblogs.com/luckiness/p/13278701.html