Search code examples
c#.netasposeaspose.wordsaspose.pdf

Using many conditions on ASPOSE <<if>> statement


I'm creating a word document to use it with Aspose for document generation.

I need to add a conditional <<if>> with many conditions:

I tried :

<<if [condition1] OR [Condition2]>>
Write something
<</if>>
<<if [condition1] AND [Condition2]>>
Write something
<</if>>

but all the syntaxes I tried failed.

Can anyone help with this?


Solution

  • You can use regular C# or Java syntax for multiple conditions:

    <<if [Condition1 || Condition2]>>
    Write something
    <</if>>
    
    <<if [Condition1 && Condition2]>>
    Write something
    <</if>>
    

    For example see the following simple code:

    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    
    builder.Writeln("<<if [1!=1 || 2==2]>>Condition is true<<else>>Condition is false<</if>>");
    builder.Writeln("<<if [1!=1 && 2==2]>>Condition is true<<else>>Condition is false<</if>>");
    
    ReportingEngine engine= new ReportingEngine();
    engine.BuildReport(doc, new object());
    
    doc.Save(@"C:\Temp\out.docx");