com.aspose.words

Class FieldIfComparisonResult

  • java.lang.Object
    • com.aspose.words.FieldIfComparisonResult
public class FieldIfComparisonResult 
extends java.lang.Object

Utility class containing constants. Specifies the result of the IF field condition evaluation.

Example:

Shows how to insert an if field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.write("Statement 1: ");

// Use document builder to insert an if field
FieldIf fieldIf = (FieldIf) builder.insertField(FieldType.FIELD_IF, true);

// The if field will output either the TrueText or FalseText string into the document, depending on the truth of the statement
// In this case, "0 = 1" is incorrect, so the output will be "False"
fieldIf.setLeftExpression("0");
fieldIf.setComparisonOperator("=");
fieldIf.setRightExpression("1");
fieldIf.setTrueText("True");
fieldIf.setFalseText("False");

Assert.assertEquals(fieldIf.getFieldCode(), " IF  0 = 1 True False");
Assert.assertEquals(fieldIf.evaluateCondition(), FieldIfComparisonResult.FALSE);

// This time, the statement is correct, so the output will be "True"
builder.write("\nStatement 2: ");
fieldIf = (FieldIf) builder.insertField(FieldType.FIELD_IF, true);
fieldIf.setLeftExpression("5");
fieldIf.setComparisonOperator("=");
fieldIf.setRightExpression("2 + 3");
fieldIf.setTrueText("True");
fieldIf.setFalseText("False");

Assert.assertEquals(fieldIf.getFieldCode(), " IF  5 = \"2 + 3\" True False");
Assert.assertEquals(fieldIf.evaluateCondition(), FieldIfComparisonResult.TRUE);

doc.updateFields();
doc.save(getArtifactsDir() + "Field.If.docx");

Field Summary
static final intERROR = 0
There is an error in the condition.
static final intTRUE = 1
The condition is true.
static final intFALSE = 2
The condition is false.
 

    • Field Detail

      • ERROR = 0

        public static final int ERROR
        There is an error in the condition.
      • TRUE = 1

        public static final int TRUE
        The condition is true.
      • FALSE = 2

        public static final int FALSE
        The condition is false.