0

Let me make it clear that I am able to access and edit(color highlight) the footers ("Footer Section xx") but not some footers, which are named as "First Page Footer - Section xx" (The Footer Section vs First Page Footer - Section are distinguish in the screenshot below).

The examples of footers that I am able to highlight: Footer Section - xx

Footer Section - xx



The example of footers that I am unable to highlight. And these footers are not only on page 1 but throughout the document: First Page Footer Section - xx

First Page Footer Section - xx

I believe these "First Page Footer Section" are the isolated footers when the option "Different 1st page footer" is selected in the Word Footer option. The question is how do I access and then ultimately highlight these "First Page Footer Section"?

The python code that I used which did highlight "Footer Section" (but couldn't highlight "First Page Footer Section") is:

filepath = r'c:\temp\doc_input_file.docx'    
doc1 = docx.Document( filepath )
for section in doc1.sections:
    for p in section.footer.paragraphs:
        for e_run in p.runs:
            e_run.font.highlight_color = WD_COLOR_INDEX.YELLOW
doc1.save( r'c:\temp\doc_output_file.docx'' )

Thank you in advance!

madhur
  • 101
  • 2
  • 7
  • there's `first_page_footer` property available in here: https://github.com/python-openxml/python-docx/blob/36cac78de080d412e9e50d56c2784e33655cad59/docx/section.py#L95. so instead of checking for `section.footer` you'd be checking for `section.first_page_footer` too. – aleksandarbos Jan 24 '23 at 09:25

0 Answers0