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 field = (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"
field.setLeftExpression("0");
field.setComparisonOperator("=");
field.setRightExpression("1");
field.setTrueText("True");
field.setFalseText("False");
Assert.assertEquals(" IF 0 = 1 True False", field.getFieldCode());
Assert.assertEquals(FieldIfComparisonResult.FALSE, field.evaluateCondition());
// This time, the statement is correct, so the output will be "True"
builder.write("\nStatement 2: ");
field = (FieldIf) builder.insertField(FieldType.FIELD_IF, true);
field.setLeftExpression("5");
field.setComparisonOperator("=");
field.setRightExpression("2 + 3");
field.setTrueText("True");
field.setFalseText("False");
Assert.assertEquals(" IF 5 = \"2 + 3\" True False", field.getFieldCode());
Assert.assertEquals(FieldIfComparisonResult.TRUE, field.evaluateCondition());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.IF.docx");
Field Summary |
static final int | ERROR = 0 | |
There is an error in the condition.
|
static final int | TRUE = 1 | |
The condition is true .
|
static final int | FALSE = 2 | |
The condition is false .
|
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
.
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.