Skip to content

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

@furrepanther

Description

@furrepanther

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