iulica / docx-mailmerge

Mail merge for Office Open XML (docx) files without the need for Microsoft Office Word.
MIT License
55 stars 7 forks source link

merge_templates for template with footer mergefields #17

Closed laythamra28 closed 5 months ago

laythamra28 commented 8 months ago

Currently I know that you can merge one document with the footer, but It would be nice if you could merge the template and create multiple documents with the footer as well.

Expected Behavior

merge_templates will also merge the footer.

Current Behavior

merge_templates will leave the footer mergefields empty.

Your Environment

iulica commented 8 months ago

There is an easy workaround for this, just do a loop and write one separate document for each data set. Implementing this feature for headers and footers would not be very very hard but the incentive to implement it is low, because it's easy to work around it. Is there an use case where this doesn't work ?

laythamra28 commented 8 months ago

Thanks for the response. Yes I was actually thinking about doing that, but then how would I merge all the documents produced to create one document? I need it do be merged in one document so that I can send one print job.

laythamra28 commented 8 months ago

Could you point me in the direction of where to make the changes so that this would work?

iulica commented 8 months ago

Well, merging the documents afterwards doesn't work. But it depends on the use case. Personally, what I do is transform the docx into pdf and then merge the pdfs together. For this one needs the Microsoft Word installed on the computer and I am using the doc-workflow python package which can automate this process. It can use the data from an excel sheet or a google sheet and the word docx template then it creates the output files, then you specify another task to transform all docx to pdf, then a third task to combine all pdfs together. It should all go smooth without user intervention. If you are interested I can provide a sample configuration.

But if I have time, I will check if I can implement the header/footer for merge_templates.

iulica commented 8 months ago

Thanks for the response. Yes I was actually thinking about doing that, but then how would I merge all the documents produced to create one document? I need it do be merged in one document so that I can send one print job.

Apparently there is a way to merge multiple word documents into one, by using insert/object/text from file. https://learn.microsoft.com/en-us/office/troubleshoot/word/merge-word-documents

iulica commented 7 months ago

Please try the new branch I created. pip install git+https://github.com/iulica/docx-mailmerge.git@headers

I'm not yet fully happy with the implementation, it will need a few changes before I release it. But you can use it already. It only works for headers/footers and not for the footnotes/endnotes. Those require a different approach, but will follow shortly, as everything needed is already in place.

laythamra28 commented 7 months ago

Thank you very much. It seemed to work for me!

iulica commented 7 months ago

It seemed ? :)

Ok, I will clean the implementation up and when I'm happy with it, I will release a new version.

iulica commented 5 months ago

released it on 0.8.0