← 返回首页
Feature: Add support for .dotx Word templates (#1532) by coderamaster · Pull Request #1537 · python-openxml/python-docx · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Feature: Add support for .dotx Word templates (#1532)#1537

Open
coderamaster wants to merge 1 commit into
python-openxml:masterfrom
coderamaster:fix/1532-dotx-template-support
Open

Feature: Add support for .dotx Word templates (#1532)#1537
coderamaster wants to merge 1 commit into
python-openxml:masterfrom
coderamaster:fix/1532-dotx-template-support

Conversation

Copy link
Copy Markdown

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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Footer

© 2026 GitHub, Inc.