Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/docx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def part_class_selector(content_type: str, reltype: str) -> Type[Part] | None:
PartFactory.part_class_selector = part_class_selector
PartFactory.part_type_for[CT.OPC_CORE_PROPERTIES] = CorePropertiesPart
PartFactory.part_type_for[CT.WML_DOCUMENT_MAIN] = DocumentPart
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
Expand Down
6 changes: 4 additions & 2 deletions src/docx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import os
from typing import IO

from docx.opc.constants import CONTENT_TYPE as CT
from docx.package import Package

Expand All @@ -21,7 +20,10 @@ def Document(docx: str | IO[bytes] | None = None):
"""
docx = _default_docx_path() if docx is None else docx
document_part = 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
Expand Down
3 changes: 3 additions & 0 deletions src/docx/opc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ class CONTENT_TYPE:
"application/vnd.openxmlformats-officedocument.wordprocessingml.docu"
"ment.main+xml"
)
WML_DOCUMENT_MACRO_ENABLED_MAIN = (
"application/vnd.ms-word.template.macroEnabledTemplate.main+xml"
)
WML_ENDNOTES = (
"application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"
)
Expand Down