Free Support Forum - aspose.com

Regarding Conditional Mail Merge in Aspose.Words forJava

Is it possible to get the values of Conditional Mail Merge from document like we do in the case of Normal Mail merge and also create a document with the conditional Mail merge feature.
I could see there are API for getting or setting normal Mail merge in Aspose API Documentation but could not find any API for getting Mail merge Info or Setting Mail Merge Info in an document.

Could you pls tell me is it possible ?
If so, could you pls show the API Docs where there is any info regardingConditional Mail Merge and also could you pls show me an Example code in Java on how to get/set mail merge in an Document

@Anbu2Win

Thanks for your inquiry. Could you please share some more detail about your use case along with template document and expected output? We will then provide you more information about your query.

I am latest version of using Aspose.words Java.
I have attached an sample ms word document containing an Conditional Mail Merge. I would like to know whether there it is possible in Aspose.words using Java to read that Conditional MailMerge content from word Document and also whether it is possible to create such Conditional MailMerge document using Aspose.words in Java. I could see that Aspose has API’s to get or set an Normal mail Merge Content but could not find any such for Conditional Mail Merge. If it is possible kindly let me know how along with some examples and could share me any useful link regarding this. Please it is quite urgent!!

MailMergeForAsposeForum.zip (11.5 KB)

@Anbu2Win

Thanks for sharing the detail. Yes, you can create and read conditional mail merge using Aspose.Words. The FieldIf class implements the IF field. Please read the members of this class and following article.
Insert and Remove Field

Please check the following code example. Hope this helps you.

com.aspose.words.Document doc = new com.aspose.words.Document(MyDir + "MailMergeForAsposeForum.docx");

doc.getMailMerge().execute(new String[] {"Address_Line_1"}, new String[] {"Canada"});
FieldIf field = (FieldIf)doc.getRange().getFields().get(1);
System.out.println(field.evaluateCondition());
System.out.println(field.getLeftExpression());
System.out.println(field.getRightExpression());
System.out.println(field.getTrueText());
System.out.println(field.getFalseText());