Document() accepts .docx and, since f49bdd1, macro-enabled .docm. Word template files — .dotx and .dotm — are still rejected, because their main-part content types are not in _WORD_MAIN_CONTENT_TYPES in docx/api.py.
Why it matters
Templates are the natural starting point for document generation: an organisation keeps its house styles, headers and numbering in a .dotx, and a pipeline should be able to open it, fill it in, and save a .docx. Today that requires renaming the file and hoping, or opening the template in Word once to convert it.
The markup inside a template is identical to a document — only the content type differs — so this is a small change, exactly parallel to the .docm support already merged.
Upstream python-openxml#363 (16 comments, open since 2017) and python-openxml#1532, with unmerged PR python-openxml#1537.
Scope
Notes
Related: #23 (Word default template) concerns the bundled default.docx, which is a different problem — this issue is about opening user-supplied templates.
Document()accepts.docxand, since f49bdd1, macro-enabled.docm. Word template files —.dotxand.dotm— are still rejected, because their main-part content types are not in_WORD_MAIN_CONTENT_TYPESindocx/api.py.Why it matters
Templates are the natural starting point for document generation: an organisation keeps its house styles, headers and numbering in a
.dotx, and a pipeline should be able to open it, fill it in, and save a.docx. Today that requires renaming the file and hoping, or opening the template in Word once to convert it.The markup inside a template is identical to a document — only the content type differs — so this is a small change, exactly parallel to the
.docmsupport already merged.Upstream python-openxml#363 (16 comments, open since 2017) and python-openxml#1532, with unmerged PR python-openxml#1537.
Scope
_WORD_MAIN_CONTENT_TYPESindocx/api.py:application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xmland the macro-enabled template equivalent.dotxunchanged keeps the template content type, so the output is still a template. Generating a document from a template means rewriting the main part content type on save. Both are legitimate; the API should let the caller choose rather than picking silently[Content_Types].xmloverride and thedocPropsneed adjusting when converting template → document.docmcommit as the model, including its test approachDocument()docstring, which currently names only.docxand.docmNotes
Related: #23 (Word default template) concerns the bundled
default.docx, which is a different problem — this issue is about opening user-supplied templates.