You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Reacted by Gonçalo Ribeiro, Bill Sim and MauritsDescamps
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...
Activity
fkromer commentedon Oct 15, 2015
Hello Pete,
thanks a lot for this hint. It would be great to have this feature in an officially released package version.
Thanks,
Florian
brewlius-cesar commentedon Nov 3, 2015
I too have a need for working with ".docm" files. Is there more to it or is @3vocati's solution adequate?
bilyum commentedon Jul 3, 2024
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...
feat: open and save .docm, .dotx and .dotm files