Skip to content

Support for '.docm' OOXML format? #212

Open

Description

@3vocati

Hello,

It seems that python-docx does not have any built in support for '.docm' OOXML documents. From the perspective of parsing this document type as a docx, there is not much difference: There are some extra document parts that support the macro language / VBA, and the Content Type for the 'word\document.xml' Document Part is 'application/vnd.ms-word.document.macroEnabled.main+xml'.

Attempting to open a '.docm' with python-docx results in the error code "file '...' is not a Word file, content type is 'application/vnd.ms-word.document.macroEnabled.main+xml'", and it does not even attempt to parse the file.

However, because a docm is basically a docx, I can get python-docx reading and writing docm files by adding the 'application/vnd.ms-word.document.macroEnabled.main+xml' Content Type to 'opc/constants.py', assigning the Content Type to a Part Factory in init.py, and adding the new Content Type to the gatekeeper check in api.py.

Is this a feature you might add to the library? So far, it seems like a small change; I haven't had any issues with my locally patched version yet, though you might know of some gotchas that I haven't encountered yet.

Thank you,

Pete

Activity

  1. fkromer commented on Oct 15, 2015

    @fkromer

    Hello Pete,

    thanks a lot for this hint. It would be great to have this feature in an officially released package version.

    Thanks,
    Florian

  2. brewlius-cesar commented on Nov 3, 2015

    @brewlius-cesar

    I too have a need for working with ".docm" files. Is there more to it or is @3vocati's solution adequate?

  3. bilyum commented on Jul 3, 2024

    @bilyum

    It's been a fair few years, but this solution worked for me. However it'd be good to know if there is a 'better' approach (given I don' t need to edit the macro, just the document content)?
    #716 doesn't appear to have been implemented in the end either...

  4. added a commit that references this issue on Nov 9, 2026
    38977fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions