Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read all footers from docx. file #868

Closed
Gilad77711 opened this issue Sep 24, 2020 · 2 comments
Closed

Read all footers from docx. file #868

Gilad77711 opened this issue Sep 24, 2020 · 2 comments

Comments

@Gilad77711
Copy link

Hello,
I read that reading footers and headers is available in the latest version of python-docx (https://python-docx.readthedocs.io/en/latest/user/hdrftr.html).

However, when I implement the code below on the attached file (71M6543F-71M6543H.docx
, I get only blanks:

from docx import Document

Reading all footers datasheet:

data_sheet = "D:\CADY\R_D\TestModules\PageNumbers\71M6543F-71M6543H.docx"
word_doc = Document(data_sheet)

for section in word_doc.sections:

footer = section.footer
for paragraph in footer.paragraphs:
    
    print(paragraph.text)

Could you please let me know how to fix this issue?

@scanny
Copy link
Contributor

scanny commented Sep 24, 2020

Looks like that document uses floating textboxes instead of paragraphs within its headers and footers. There is no API support for those yet in python-docx unfortunately.

If you control these documents you can achieve the same effect with paragraphs and tabs. If not and you just need to read them, you'll need to dig into the XML. You can get a start at seeing what the XML for those currently is with:

print(footer._element.xml)

Then you could possibly use XPath expressions to get the contents or one of some other methods. If you post the XML from one you're interested in I may be able to be more specific.

@scanny scanny closed this as completed Dec 27, 2020
@javaDer
Copy link

javaDer commented Aug 4, 2021

tlks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants