diff --git a/src/docx/__init__.py b/src/docx/__init__.py index fd06c84d2..b3f153cf5 100644 --- a/src/docx/__init__.py +++ b/src/docx/__init__.py @@ -44,6 +44,8 @@ def part_class_selector(content_type: str, reltype: str) -> Type[Part] | None: PartFactory.part_type_for[CT.OPC_CORE_PROPERTIES] = CorePropertiesPart PartFactory.part_type_for[CT.WML_COMMENTS] = CommentsPart PartFactory.part_type_for[CT.WML_DOCUMENT_MAIN] = DocumentPart +# Support for macro enabled template +PartFactory.part_type_for[CT.WML_DOCUMENT_MACRO_ENABLED_MAIN] = DocumentPart PartFactory.part_type_for[CT.WML_FOOTER] = FooterPart PartFactory.part_type_for[CT.WML_HEADER] = HeaderPart PartFactory.part_type_for[CT.WML_NUMBERING] = NumberingPart diff --git a/src/docx/api.py b/src/docx/api.py index aea876458..6585e878a 100644 --- a/src/docx/api.py +++ b/src/docx/api.py @@ -25,7 +25,10 @@ def Document(docx: str | IO[bytes] | None = None) -> DocumentObject: """ docx = _default_docx_path() if docx is None else docx document_part = cast("DocumentPart", Package.open(docx).main_document_part) - if document_part.content_type != CT.WML_DOCUMENT_MAIN: + if document_part.content_type not in [ + CT.WML_DOCUMENT_MAIN, + CT.WML_DOCUMENT_MACRO_ENABLED_MAIN, + ]: tmpl = "file '%s' is not a Word file, content type is '%s'" raise ValueError(tmpl % (docx, document_part.content_type)) return document_part.document diff --git a/src/docx/opc/constants.py b/src/docx/opc/constants.py index a3d0e0812..d31003e9a 100644 --- a/src/docx/opc/constants.py +++ b/src/docx/opc/constants.py @@ -135,6 +135,9 @@ class CONTENT_TYPE: WML_DOCUMENT_MAIN = ( "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" ) + WML_DOCUMENT_MACRO_ENABLED_MAIN = ( + "application/vnd.ms-word.template.macroEnabledTemplate.main+xml" + ) WML_ENDNOTES = "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml" WML_FONT_TABLE = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml" WML_FOOTER = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml" @@ -303,4 +306,4 @@ class RELATIONSHIP_TYPE: WORKSHEET_SOURCE = ( "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheetSource" ) - XML_MAPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps" + XML_MAPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps" \ No newline at end of file