from docx import Document
def remove_headers_and_footers(docx_path):
doc = Document(docx_path)
for section in doc.sections:
# 删除页眉和页脚
section.different_first_page_header_footer = False
section.header.is_linked_to_previous = True
section.footer.is_linked_to_previous = True
doc.save(docx_path)
docx_path = "test.docx" # 替换为您的 Word 文件路径
remove_headers_and_footers(docx_path)
Python删除Word文档的页眉和页脚
最新推荐文章于 2024-09-09 00:00:00 发布