Open leonatez opened 4 years ago
Instead of using with to open the existing document, use MailMerge function to read the file object. To fix the error use the below code:
from mailmerge import MailMerge document = MailMerge('input.docx') document.merge(field1='docx Mail Merge', field2='Can be used for merging docx documents') document.write('output.docx')
I'm new to this module. I tried exactly your example but it says below exception:
Traceback (most recent call last): File "/Users/mac/Downloads/BBEditRunTemp-test.py", line 6, in
document.write('output.docx')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mailmerge.py", line 121, in write
for zi in self.zip.filelist:
AttributeError: 'NoneType' object has no attribute 'filelist'
The code is here: from mailmerge import MailMerge with MailMerge('input.docx') as document: ... document.merge(field1='docx Mail Merge', field2='Can be used for merging docx documents') document.write('output.docx')