Skip to content

Commit

Permalink
Add support for .docm
Browse files Browse the repository at this point in the history
  • Loading branch information
tssujt committed Jun 4, 2024
1 parent 0cf6d71 commit b2bf8a5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/docx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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_MACRO_ENABLED_MAIN] = DocumentPart
PartFactory.part_type_for[CT.WML_DOCUMENT_MAIN] = DocumentPart
PartFactory.part_type_for[CT.WML_FOOTER] = FooterPart
PartFactory.part_type_for[CT.WML_HEADER] = HeaderPart
Expand Down
5 changes: 4 additions & 1 deletion src/docx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_MACRO_ENABLED_MAIN,
CT.WML_DOCUMENT_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 @@ -205,6 +205,9 @@ class CONTENT_TYPE:
"application/vnd.openxmlformats-officedocument.wordprocessingml.docu"
"ment.glossary+xml"
)
WML_DOCUMENT_MACRO_ENABLED_MAIN = (
"application/vnd.ms-word.document.macroEnabled.main+xml"
)
WML_DOCUMENT_MAIN = (
"application/vnd.openxmlformats-officedocument.wordprocessingml.docu"
"ment.main+xml"
Expand Down

0 comments on commit b2bf8a5

Please sign in to comment.