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

IF Conditionals #22

Open dwasyl opened 1 week ago

dwasyl commented 1 week ago

Having had some trouble tracking down how to make IF statements work but then eventually noticed the docs:

{ IF "{ MERGEFIELD reason }" <> "" "Reason: { MERGEFIELD reason }" }

_If the fields are nested inside other fields, the outer fields need to be updated in Word. This can be done by selecting everything (CTRL-a) and then update the fields (F9). There is a way to force the Word to update fields automatically when opening the document. docx-mailmerge can set this setting when saving the document. You can configure this feature by using the auto_update_fields_onopen parameter. The value always will set the setting regardless if needed or not and the value auto will only set it when necessary (when nested fields exist). The default value no will not activate this setting.

Based on that, I've been using the auto_update_fields_on_open="auto" setting which works fine, but requires opening the document and saving. In some of my use cases it would be handy to generate a complete Word document and send that the to end-user or another, but when the field needs updating it seems a bit complicated.

Would it be possible for docx-mailmerge to handle the conditional statements as part of the processing, or is that logic too complicated/unavailable?