我想删除word文档中使用Python函数包含多个页面和部分的所有页眉和页脚。我尝试使用:
from docx import Document
document = Document('new.docx')
for section in document.sections:
header = section.header
header.is_linked_to_previous = True
document.save('mydoc.docx')header.is_linked_to_previous = True正在删除文档中的所有页眉和页脚,但是如果在页眉或页脚中的Word中启用了“不同的第一页”选项,则这是无效的。我要删除所有的事件。

发布于 2022-04-07 15:08:37
您只需通过python将不同的第一页设置为False即可。
from docx import Document
document = Document(doc)
for section in document.sections:
section.different_first_page_header_footer = False
section.header.is_linked_to_previous = True
document.save(edited_doc)https://stackoverflow.com/questions/70125668
复制相似问题