-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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.