Home:ALL Converter>Empty header sections (python-docx)

Empty header sections (python-docx)

Ask Time:2019-07-22T00:20:43         Author:Cheers

Json Formatter

I am trying to modify word documents using python-docx. Everything is working fine for the documents' body sections, but it gets trickier for the header sections, which I currently am not able to access.

Below is the code I've executed for trying to read the content of the header sections in my document.

import os
from docx import Document

os.chdir('/Users/rtsg/Desktop/Docx')
document = Document('report_v1.docx')

sections = document.sections
for section in document.sections:
    header = section.header
    for paragraph in header.paragraphs:
        print(paragraph.text)

When trying to print the content of the header sections, I get nothing returned (empty strings I guess).

Did someone experience a similar issue and managed to solve it ? Are there some workarounds for modifying the content of the header section ?

Author:Cheers,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/57134955/empty-header-sections-python-docx
yy