Bouke / docx-mailmerge

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

Feature-request: Recursive mail merges #83

Open utimcraig opened 4 years ago

utimcraig commented 4 years ago

I'd like to be able to have a mail merge field in my word document template, and then merge in new mail merge fields. In other words something like this: In template:

List of activities:
<<Field_1>>

And then be able to replace <> new merge fields like:

<> <> <> <>

Or perhaps there is a better way like using a python variable to insert a mail merge field?

Expected Behavior

I'd like to be able to insert new mail merge fields into a word document, to make a new template that would then later be subjected to a second, standard mail merge from an excel/csv file.

Current Behavior

It's unclear to me how I can insert a mail merge field into a template using the package

Possible Solution

This could jut be an education problem for myself, but I searched around and couldn't find an answer

Context

I have to generate a lot of word document quotes for different kinds of services, so I'm trying to automate the setting up of a template, which then needs to be updated for each customer with different numbers of activities each time. These activities then have their own titles, descriptions, timelines, etc.

So what I want to have is the following flow: Start: Base Template -> modified template with mail merge fields -> final merge using data from excel that contains descriptions, titles, etc

Your Environment

I'm using windows and either stable version of python

JDeeth commented 2 years ago

I have the same requirement: my job requires me to produce a lot of .docx files containing {MAILMERGE} fields.

However does it need to be a recursive mailmerge? The initial template could be marked up with simple text sequences e.g. {{field_1}} or [[header]], and only the output files need proper Ctrl-F9 {MAILMERGE} fields.

I think inserting Ctrl-F9 fields like {MAILMERGE} might be outside the scope of this module, which is for populating those fields. Still looking for a module for doing this!