Skip to content

Conversation

@coderamaster
Copy link

Description

Fixes #1532.

Adds support for loading Word template files (.dotx) with python-docx.Document().


Problem

Loading a .dotx file currently raises a ValueError due to an unsupported content type. Even if bypassed, the part factory creates a generic Part instead of DocumentPart, causing an AttributeError.


Solution

Treat .dotx templates the same as .docx documents, which matches the OOXML spec.

Changes:

  • Accept Word template main content type
  • Map template content type to DocumentPart
  • Add tests for .dotx loading

Testing

  • Added tests for .dotx files
  • Verified with a real template created in Microsoft Word
  • Confirmed .docx behavior remains unchanged

- Added WML_TEMPLATE_MAIN content type constant
- Updated Document() to accept both .docx and .dotx files
- Added part factory mapping for template content type
- Added tests for .dotx template loading
- Fixes python-openxml#1532
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