Free Support Forum - aspose.com

Is there a way to have "IF" statements executed in the output?

The word template that I am using it has 2 pages, there is an IF statement that takes either page one or page 2 depending on a merge field.

If I do mailmerge in MS Word, the resulting file has the IF statement already executed, i.e. the output contains only ONE page, and the IF statement from the template is not there anymore.

But with Aspose.Words, both pages are still there and also the IF statement (just like a template). When I open the output word document, and press ALT+F9, I can see IF statement and the 2 pages. But if I do the same in MS Word, then I don't see the IF, and only one page is there (with the IF already executed)

So... is there a way to "execute" the IF statement in Aspose.Words?

Hi Michael,


Thanks for your inquiry. Could you please attach your input template Word document here for testing? I will investigate the issue on my side and provide you more information.

Best Regards,

I uploaded a test document.

In the output file, I sould have only ONE image (without the IF statement), if you press ALT+F9 in MS Word, you can see that it still looks like a template.

Hi Michael,


Thanks for your inquiry. Actually, as long as you use the latest versions of Aspose.Words there is an in-built feature to remove the container IF field automatically. Please try using MailMergeCleanupOptions.RemoveContainingFields flag as follows:

Document doc = new
Document(@“C:\Temp\TestMerge_IF_Img.docx”);

doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveContainingFields;

doc.MailMerge.Execute(new string[] { "LegalEntity" }, new object[] { "TEST1" });

doc.Save(@“C:\Temp\out.docx”);


I hope, this helps.

Best Regards,

That's what it was! THANK YOU!

I have 2 more question not related to this one, I hope you don't mind:

1) Can you please show me how to open a document and read all the text (from all the pages) from the document? not interested in formatting, only the text.

2) Second, if I have 2 (or more) documents (office 2010), how can I join/combine the documents into one big docx?

Hi Michael,


Thanks for your inquiry.

1) I would suggest you please read the following article on Saving Document in the Plain Text format. You may also want to look into passing an instance of the TxtSaveOptions class when saving:
http://www.aspose.com/docs/display/wordsnet/Save+in+the+Plain+Text+Format

2) There are two most authentic ways you can use for merging documents into another Word document e.g:

http://www.aspose.com/docs/display/wordsnet/How+the+AppendDocument+Method+Works
http://www.aspose.com/docs/display/wordsnet/How+to++Insert+a+Document+into+another+Document

Best Regards,

Excelent! You gave me everything I need. Thank You!

Hi Michael,


Thanks for your feedback. Please let us know any time you have any further queries. We’re always glad to help you.

Best Regards,