[英]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.