Conditional block in nested Mail Merge Regions

I am attempting to insert a conditional block into a Mail Merge Region directly from LibreOffice writer (since I cannot touch the code)
I am attaching an image of how I am attempting to insert the command fields
(p.s. the table contained in the condition should not be shown if the “has_children” field is false)
Thanks for the help
Immagine 2023-06-06 172722.png (50.1 KB)


It seems you are using Aspose.Words API, correct me if I am wrong? I am moving your thread to respective forum where Aspose.Words team will assist you on your query/issue.

yes, sorry for the mistake

You can easily achieve what you need using IF field in your MS Word template document. Field codes: IF field - Microsoft Support in the condition you can insert a merge field or a bookmark and then update the condition upon execution mail merge or setting bookmark value using Aspose.Words. For example, see the screenshot of the template document and the code to execute mail merge using Aspose.Words.

Document doc = new Document("C:\\Temp\\in.docx");
CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

If the output format is supposed to be MS Word document, you can also call Document.unlinkFields() method or MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS (if you want to remove only the IF field) before saving, in this case IF field will be removed from the document and only the result will be preserved. (10.3 KB)

However, I still haven’t figured out how to enter the command fields…
I am entering them via a database made in excel like this (see attached)
The condition should be inserted in the TableStart and TableEnd that you see in the picture, but I don’t know what is the correct way to do it
help_aspose_word.png (3.5 KB)

@lorenzo.alessi Since you prefer not to modify the source code, I would recommend using the MS Word application itself to insert the IF field, as I explained in my previous reply. This approach should be feasible and allow you to achieve the desired functionality.

However, if using the MS Word application is not a viable solution for you, I kindly request that you provide more details about your application and its data flow. Understanding the inner workings of your application will enable us to provide more tailored and effective support. The more information we have, the better we can assist you in finding an alternative solution.