from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.shared import Pt from docx import Document w=Document(r\'E:\word练习\a.docx\') w.sections.odd_and_even_pages_header_footer=True #启动奇偶页不同 第一节=w.sections[0] 偶数页=第一节.even_page_header #获取偶数页的页眉 页眉=偶数页.paragraphs[0].add_run(\'这是偶数页的页眉\') 页眉.font.size=Pt(20) 偶数页.paragraphs[0].alignment=WD_ALIGN_PARAGRAPH.CENTER w.save()