If , ElseIf in MergeField Aspose Word

Can anyone give me a proper syntax for
if, else if and else Mergefields used in a Word document.
For example:
ifelse json.docx (12.2 KB)

I need a if and another if or else if condition to check whether the questiontype is text or picklist, based on that i need to print the values.

@ArunaAP In MS Word there is no ElseIf fields. You can achieve your requirements using nested IF fields. For example you can use field code like this:

{ IF "{ MERGEFIELD condition }" = "true" "{ IF "{ MERGEFIELD condition2 }" = "true" "ElseIf True Value" "ElseIf False Value" }" "False Value" }

Your requirements can be easily implemented using LINQ Reporting Engine and the following syntax:

<<if [conditional_expression1]>>
<<elseif [conditional_expression2]>>

Please see our documentation for more information:

Can you please refer the doc which I attached, I need to fetch the value based on the question Type

@ArunaAP If I understand correctly you are using Aspose.Words for Cloud. Could you please confirm. If so I will move your question into the appropriate forum.

As for LINQ Reporting Engine you can use the following syntax:

<<foreach [q in listOfQuestions]>>
<<if [q.QuestionType == “picklist”]>>
This is picklist question
<<elseif [q.QuestionType == “text”]>>
This is text question
This is default option

Here is the code to fill the document with data:

JsonDataSource ds = new JsonDataSource(@"C:\Temp\data.json");
Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, ds, "listOfQuestions");

in.docx (12.8 KB)
out.docx (10.1 KB)

If it is required to use mail merge, then you can simply use several IF fields even without nesting them:

{ IF "{ MERGEFIELD QuestionType }" = "picklist" "This is picklist question" "" }
{ IF "{ MERGEFIELD QuestionType }" = "text" "This is picklist question" "" }

The template might be look like this (press Alf+F9 to see field codes):
mail_merge.docx (12.6 KB)

Yes, I am using Aspose.Words for cloud.
QuestionTable.docx (14.0 KB)

and this is my syntax, i need to print it in a single table

This topic has been moved to the related forum: If , ElseIf in MergeField Aspose Word - Free Support Forum - aspose.cloud