Skip to content

how to copy a docx into a template with headers? #364

@schoreZ

Description

@schoreZ

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:

  1. read all the contents from the source docx in sequence.
  2. 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:

  1. What should I 'copy' from the source file? not paragraphs. Is it elements, blocks, parts, sections, or something else?
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions