Skip to content

feat: support loading .dotx Word templates - #1586

Open
ChenfromChina123 wants to merge 2 commits into
python-openxml:masterfrom
ChenfromChina123:fix/dotx-template-support
Open

feat: support loading .dotx Word templates#1586
ChenfromChina123 wants to merge 2 commits into
python-openxml:masterfrom
ChenfromChina123:fix/dotx-template-support

Conversation

@ChenfromChina123

Copy link
Copy Markdown

What does this PR do?

Allows Document() to load .dotx Word templates. Previously it raised ValueError: file '...' is not a Word file because the template main part has content type application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml, which was not recognized.

Closes #1532

Changes

  • src/docx/opc/constants.py: add WML_TEMPLATE_MAIN content type constant.
  • src/docx/__init__.py: register DocumentPart for WML_TEMPLATE_MAIN.
  • src/docx/api.py: Document() now accepts both WML_DOCUMENT_MAIN and WML_TEMPLATE_MAIN.

Verification

  • python -m py_compile passes on all changed files.
  • PartFactory.part_type_for[WML_TEMPLATE_MAIN] resolves to DocumentPart.

ChenfromChina123 and others added 2 commits August 10, 2026 22:34
The example calls add_picture('monty-truth.png') which raises
FileNotFoundError when the file is not present in the working
directory. Wrap it in a try/except so the example runs out of
the box.

Closes python-openxml#128

Co-Authored-By: AtomCode (deepseek-v4-flash) <[email protected]>
Document() rejected .dotx templates because their main part has
content type application/vnd.openxmlformats-officedocument.
wordprocessingml.template.main+xml, which was not recognized.
Add WML_TEMPLATE_MAIN constant, register DocumentPart for it, and
accept it in Document().

Closes python-openxml#1532

Co-Authored-By: AtomCode (deepseek-v4-flash) <[email protected]>
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

Successfully merging this pull request may close these issues.

ValueError when loading .dotx Word template – lack of native template support

1 participant