jaolstad
jaolstad

Reputation: 605

python-docx v0.8.10 - Unable to read/add header

Attempting to create a new document with headers and footers, but without success.

My code:

doc = Document()
section = doc.sections[0]
header = section.header
...

Unfortunately I am not able to figure out how to "initialize" the header section, as this code fails, throwing the following exception:

header = sections[0].header
AttributeError: 'Section' object has no attribute 'header'

I have also tried the approach creating a Word document with headers and footers beforehand and loading into python-docx, but unfortunately it ends with the same result.

Anyone able to point me in the right direction?

Upvotes: 0

Views: 663

Answers (1)

scanny
scanny

Reputation: 29031

Sounds like a version problem. v0.8.8 would give you that error, for example, since headers were added in the last release. You can check the version that is actually executing with:

import docx
print(docx.__version__)

Could be an environment mixup or something like that. If you need to reinstall, try this:

pip install python-docx==0.8.10

just to make sure you're getting the version you expect and not perhaps a cached earlier version.

Upvotes: 1

Related Questions