I am trying to add headers to a series of docx files. But since python-docx does not provide header manipulation, I'm thinking to copy the source files' contents (with all its figures, images, tables styles, etc.) to a template file with a header, as the docx documentation says it politely preserves the headers of an opened docx.
So I will do this in two steps:
- read all the contents from the source docx in sequence.
- wrote all the contents with its formats to the existing template file.
But having read the documentation, googled solutions, I have problems that the documentation doesn't tell me:
- What should I 'copy' from the source file? not paragraphs. Is it elements, blocks, parts, sections, or something else?
- How do I iterate these 'to copy' objects? and how do I put them into a new file?
I see some related problems using methods that do not exist in the docx 0.8.6 documentation, such as
paragraph._element
p.getparent().remove(p)
p._p = p._element = None
document.body.append(element)
xpath
etc.
Is it because they are previous version features that will not be supported in the future?
If they are essential, where should I find their usage?
Thank you very much.
I am trying to add headers to a series of docx files. But since python-docx does not provide header manipulation, I'm thinking to copy the source files' contents (with all its figures, images, tables styles, etc.) to a template file with a header, as the docx documentation says it politely preserves the headers of an opened docx.
So I will do this in two steps:
But having read the documentation, googled solutions, I have problems that the documentation doesn't tell me:
I see some related problems using methods that do not exist in the docx 0.8.6 documentation, such as
paragraph._element
p.getparent().remove(p)
p._p = p._element = None
document.body.append(element)
xpath
etc.
Is it because they are previous version features that will not be supported in the future?
If they are essential, where should I find their usage?
Thank you very much.