Skip to content

added support for .docm files #716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

EmanueleCannizzaro
Copy link

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

@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

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

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

@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

I'm looking forward to this PR as well!

@rurubino1
Copy link

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

@tsuga
Copy link

tsuga commented Sep 12, 2021

I'm looking forward to this PR as well!

@DanielPekar-RJC
Copy link

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

Copy link

@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

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

Please merge :(

@fnicollet
Copy link

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

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

@ir0nstone
Copy link

Why is this still not merged?

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.