单独设置首页的页眉页脚

from  docx import  Document
from  docx.shared  import  Pt
from  docx.enum.text  import  WD_ALIGN_PARAGRAPH  #导入对齐库
文件=Document(r'E:\word练习\页眉页脚.docx')
第一节=文件.sections[0]
第一节.different_first_page_header_footer=True  #设置首页不同
首页对象=第一节.first_page_header
页眉=首页对象.paragraphs[0].add_run('这是页眉')
页眉.font.size=Pt(12)
首页对象.paragraphs[0].alignment=WD_ALIGN_PARAGRAPH.CENTER
首页对象=第一节.first_page_footer
页脚=首页对象.paragraphs[0].add_run('这是页脚')

文件.save(r'E:\word练习\首页不同.docx')

 

posted @ 2020-07-12 10:54  马蹄哒哒  阅读(764)  评论(0编辑  收藏  举报