.NET - IF and Mail Merge - Conditional

Hello,


I'm using Aspose.Words.dll (Version 13.1) in a Visual Studio 2012 project (using MS Word 2010 template files).
Inserting values in mergefields through Aspose API works fine!


I want to define a condition in a merge field in WORD in order to display a value.

IF “{ MERGEFIELD DOCUMENT_LANGUAGE }” = “FR” “True text” “False text” \* MERGEFORMAT

I've also add the following merge field above my condition

«DOCUMENT_LANGUAGE»

Here is the result:

FR

False text

So even if the condition is true (as the result of the first merge field is FR) , 'False text' is always displayed.

I don't understand why ?

I've also tried a more simple condition

IF "{0=0}" "true text" "false text" \* MERGEFORMAT

But after the generation, 'Error! Unknown op code for conditional.' is displayed ??? I expect to have 'true text' ...


Could you, please, give me an example or help me ?

Thanks in advance

Best regards

Jean-Noël

Hi Collin,


Thanks for your inquiry. Please note that Aspose.Words tries to mimic the same behavior as MS Word do.
jean-noel.collin:
I want to define a condition in a merge field in WORD in order to display a value.

IF “{ MERGEFIELD DOCUMENT_LANGUAGE }” = “FR” “True text” “False text” * MERGEFORMAT

I have worked with your document. The above IF field does not contain the mail merge field. Right click on the mail merge filed by using MS Word and select ‘Edit field’, you will get only IF filed. Please see the attached images for detail.

The mail merge filed ({ MERGEFIELD DOCUMENT_LANGUAGE }) in your template is a simple text. Please insert the mail merge filed correctly in IF field. I have modified your document and attached to this post for your kind reference.
jean-noel.collin:
IF “{0=0}” “true text” “false text” * MERGEFORMAT

But after the generation, ‘Error! Unknown op code for conditional.’ is displayed ??? I expect to have ‘true text’ …

Please modify the IF field condition as shown below. I have modified the IF field in your document and attached it with this post.

{ IF 0 = 0 “true text” “false text” * MERGEFORMAT}

Moreover, In the following IF example, if you change the condition “{0=0}” to “{0=1}”, result will also be “true text”. Please modify the IF condition as shown above to get correct result.

{IF “{0=0}” “true text” “false text” * MERGEFORMAT * MERGEFORMAT }

Please read more about examples of IF fields from here. Hope this answers your query. Please let us know if you have any more queries.

Hello,

Thanks for your answer.

I've discovered the ALT+F9 functionality and also all the correct syntax.

Have a nice day

Best regards

Jean-Noël

Hi Jean,


Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.