Closed laythamra28 closed 5 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 ?
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.
Could you point me in the direction of where to make the changes so that this would work?
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.
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
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.
Thank you very much. It seemed to work for me!
It seemed ? :)
Ok, I will clean the implementation up and when I'm happy with it, I will release a new version.
released it on 0.8.0
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