← 返回首页
ValueError when loading .dotx Word template – lack of native template support · Issue #1532 · 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

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

New issue
New issue

Description

Attempting to instantiate a Word template (.dotx) using python-docx.Document() fails with a ValueError. The file opens normally in Microsoft Word and conforms to the standard OOXML template structure.

Steps to Reproduce

from docx import Document
doc = Document(".dotx")

Actual Behavior

ValueError: file '.dotx' is not a Word file,
content type is 'application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml'

Expected Behavior
The library should be able to load .dotx templates just like .docx documents, allowing developers to:

Read and apply existing style definitions

Retain header/footer content, watermarks, and embedded assets

Save new .docx files that preserve template formatting

Environment

python-docx version: (run pip show python-docx to confirm)

Python version: 3.11+

Platform: Linux/Windows

Use Case
Corporate document generation workflows (e.g., Alignment Guard Labs) depend on .dotx templates for visual standards and branding. The current limitation forces manual template application in Word post-generation.

Proposed Enhancement
Add native .dotx support or a helper API such as Document.from_template(path) to copy all style and part relationships into a new .docx.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotx/docmAlternate DOCX content types that should parse fine.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Footer

      © 2026 GitHub, Inc.