[英]Extract Page 1 Header from Word Doc
我正在尝试从 MS Word 文档 (.docx) 的第 1 页 Header 中提取多行文本。 我正在使用 python.docx 但无法确定我需要获得多具体才能仅获得第一页 header。
代码目前是:
from docx import Document
document = Document("path.docx")
section = document.sections[0]
header = section.header
print(header.paragraphs[0].text)
使用 output:“文件名;史密斯;页”
我所指的内容的屏幕截图链接为 Headers 与 Running Header。 我想要 Header,我不关心 Running Header: Header 1 Running ZBF50D5E5361106F7AFE792
任何帮助表示赞赏! I've looked at the documentation for headers in general ( https://python-docx.readthedocs.io/en/latest/user/hdrftr.html ) but it does not go into specifics for dealing with the Different First Page Header feature MS Word。
它们不是按页排列的,但有主(奇数页)header、偶数页 header 和首页 header。
没有 Sections(0),数字从 1 开始。每个文档至少有一个 section。 如果您需要有关它们以及页眉和页脚的更多信息,这是我的 web 页面。
The header on the first page will be either the first-page header of Section 1 or the primary header of Section 1. The code for the primary is Activedocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text
; 第一页是Activedocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Text
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.