Python-docx: Is there anyway that I can read the header of the document?

Created on 22 Jul 2017  路  2Comments  路  Source: python-openxml/python-docx

I find the document http://python-docx.readthedocs.io/en/latest/dev/analysis/features/header.html .But it said that it is under development. So I wonder is there anyway that I can read the header or footer of a docx?

Most helpful comment

When you parse a docx file with docx.Document(docx_file_path), you would got a Document object, like this:
doc = docx.Document(docx_file)
and then you can get the xmls of headers or footers in the docxfile by:
headers = [x.blob.decode() for x in doc.part.package.parts if x.partname.find('header')>0]
then you could use some moudle like lxml to parse the xml texts.

All 2 comments

When you parse a docx file with docx.Document(docx_file_path), you would got a Document object, like this:
doc = docx.Document(docx_file)
and then you can get the xmls of headers or footers in the docxfile by:
headers = [x.blob.decode() for x in doc.part.package.parts if x.partname.find('header')>0]
then you could use some moudle like lxml to parse the xml texts.

Header and footer support will be released with v0.8.8 in the next day or two. Until then a working version is available on the spike-header branch.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

avvRobertoAlma picture avvRobertoAlma  路  7Comments

sskadit picture sskadit  路  4Comments

JiyhonLiu picture JiyhonLiu  路  3Comments

aekoch picture aekoch  路  7Comments

bendaojiu picture bendaojiu  路  5Comments