2

I think this question is pretty self explanatory. From what I've read of the python-docx documentation, it seems that the header and footer must be exactly the same on every page, which of course makes adding page numbers difficult. Is this possible?

adamcircle
  • 694
  • 1
  • 10
  • 26

2 Answers2

1

Adding headers and footers is a feature not yet implemented.

However...

  • If it is an existing document you want to add headers and footers to you can call a VBA-macro. I recently posted a way to do that (https://stackoverflow.com/a/44767400/7386332)

  • If it is a new document then you can indeed go on and create a template document first and then open it up and continue editing as described by scanny.

Anton vBR
  • 18,287
  • 5
  • 40
  • 46
0

A Word document produced by python-docx will preserve any headers and footers present in the "template" document. So the way to get those is to create a "starting" document that has the headers and footers you're after.

A header or footer can contain a page number field, which is automatically updated with the current page number at display and/or print time. This is added using the Insert > Field > Page Number menu option in Word. Different Word versions do this slightly differently, but this should get you close enough to find it on your version. Otherwise a search on "Insert page number Word 2013" with your version will find you many resources.

scanny
  • 26,423
  • 5
  • 54
  • 80