We have a word document where we wanted to display text based on condition evaluation so I would like to understand whether the same is possible if yes kindly provide me with sample code:
The sample text in word document as follows:
Display below only if WORK_STATE=NJ
Sample text sample text .
Display above only if WORK_STATE=CA
Sample text sample text
Hi there,
Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. You can work with IF fields and mail merge using Aspose.Words.
Could you please attach your input and expected output Word documents here for our reference? We will then provide you more information about your query along with code.
Hi
Thanks for your reply.
PFA three documents : 1) master 2) output of document IF WORK_STATE=TN 3) output of document IF WORK_STATE=AP
While processing the document i will get WORK_STATE VALUE FROM database and the same will be evaluated during document process and display output.
Regards
Satyadev
Hi Satyadev,
Thanks for your inquiry. In your case, we suggest you following solution.
- Insert the IF field in your template document
- Insert mail merge field in left part of the comparison expression of IF field.
- Perform mail merge using Aspose.Words to get the required output.
Please read following documentaion links for your kind reference. We have attached sample input document with this post for your kind reference.
Simple Mail Merge Explained
How to Execute Simple Mail Merge
Hi
I have read that but my question was how do i hide text below if condition based on evaluation.
if (state = “TamilNadu”)
sample text sample text
if (state = “Banglore”)
sample text1 sample text1
during evaluation if state value was Delhi then i want to remove the whole text which was mentioned above. if state value was Banglore i want to display only sample text sample text1 and remove above one in the output document.
Regards
Satyadev
Hi Satyadev,
Thanks for your inquiry. Please use following code example to achieve your requirements. We have attached the input and output documents with this post for your kind reference.
Document doc = new Document(MyDir + “input.docx”);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS |
MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS);
doc.getMailMerge().execute(new String[] { “WORK_STATE” }, new String[] { “Banglore” });
doc.save(MyDir + “Out.docx”);