单独设置首页的页眉页脚
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\')
版权声明:本文为luckiness原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。