Skip to content

added support for .docm files#716

Open
EmanueleCannizzaro wants to merge 2 commits intopython-openxml:masterfrom
EmanueleCannizzaro:master
Open

added support for .docm files#716
EmanueleCannizzaro wants to merge 2 commits intopython-openxml:masterfrom
EmanueleCannizzaro:master

Conversation

@EmanueleCannizzaro
Copy link
Copy Markdown

A long lasting issue with python-docx has been the lack of support of macro-enabled files.
A patch has been created a long time ago but I was never merged in master branch.

It is identical approach as suggested in #673.

Copy link
Copy Markdown

@mfreeborn mfreeborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of:
if document_part.content_type not in [CT.WML_DOCUMENT_MAIN, CT.WML_DOCUMENT_MACRO_ENABLED_MAIN]:

Why not:
if document_part.content_type not in {CT.WML_DOCUMENT_MAIN, CT.WML_DOCUMENT_MACRO_ENABLED_MAIN}:

I.e. change the collection type to a set. I feel that it's just better practice when all you want to do is test for membership.

@JeanMRog
Copy link
Copy Markdown

This would be great if this pull request be accepted as it is super simple & will avoid all of us that need to load .docm files to do dirty setups either by modifying your library locally or overloading it.
Cheers.

@nickyu42
Copy link
Copy Markdown

I agree that it would be great if this gets merged, currently I use a script that uses soffice to convert .docm files to .docx, which takes some time for each document

@JeanMRog
Copy link
Copy Markdown

@scanny Is there any blocking point preventing the acceptance of this pull request ? it seems to pass the checks.
I implemented the modifications locally & it is dirty but it works very well.
Is there something we can do to help it move it forward?
It might seem a detail for you but for people working with .docm files this is a really painful problem.
Cheers

@taiebnoe
Copy link
Copy Markdown

I'm looking forward to this PR as well!

@rurubino1
Copy link
Copy Markdown

Hi, this is great! Can we get it merged asap please?

@cobnett3
Copy link
Copy Markdown

I'm looking forward to this PR as well!

@DanielPekar-RJC
Copy link
Copy Markdown

Worked great for me when I implemented this patch on my own - able to work with docx and docm files without issue.

Copy link
Copy Markdown

@DanielPekar-RJC DanielPekar-RJC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK

@kaixxx
Copy link
Copy Markdown

kaixxx commented May 4, 2023

Works very nice. Macros are preserved after saving, everything is fine.
Would be great having this finally integrated!

@Anon-Exploiter
Copy link
Copy Markdown

Please merge :(

@fnicollet
Copy link
Copy Markdown

Hello,

It seems like there are some forks of python-docx just for this purpose, including one called "python-docx-docm". Turns out it doesn't work either as you get an error:

AttributeError: 'Part' object has no attribute 'document'

Because one line is missing (the modification of init.py in this MR). It can be monkey patched on-the-fly in the code, with this line of code:

docx.opc.part.PartFactory.part_type_for[docx.opc.constants.CONTENT_TYPE.WML_DOCUMENT_MACRO_ENABLED_MAIN] = docx.parts.document.DocumentPart

With this modification, docm file can be opened with the "python-docx-docm" forks. But it would be best if this MR could be merged

@DanielDM325
Copy link
Copy Markdown

Any news on this being implemented? Seems like an easy issue.

@ir0nstone
Copy link
Copy Markdown

Why is this still not merged?

@BrianMer
Copy link
Copy Markdown

BrianMer commented Jul 9, 2025

Any news on that? If we want only to change the body of the document and not the macros, it seems like a pretty good fix.

@tcornwall-ag
Copy link
Copy Markdown

Just adding that for my use cases this is PR would add a lot of value. Would be great to see it merged in!

@SirJonithan
Copy link
Copy Markdown

Hi @scanny, is there anything that can be done to to help this PR being merged?

@mjuhlin1
Copy link
Copy Markdown

mjuhlin1 commented Apr 2, 2026

Hi @scanny .
It would bring great value to get this in. We are trying to get rid of all old forked dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.