Evaluate fields using java


#1

Hi,

Is it possible to

  1. identify fields in paragraph or table cell nodes and
  2. evaluate those

for.e.g., {IF 1=1 “TRUE” “FALSE”*MERGEFORMAT} should evaluate to “TRUE”.

Could you please provide some examples?

Thanks.


#2

@vgm

Thanks for your inquiry.

You can use Node.Range.Fields property to get the Fields collection that represents all fields in the range.

Please use FieldIf.EvaluateCondition method to evaluate the condition.


#3

Hi Tahir,

Thanks. I did try accessing getFields on a node’s range. It appears that only formfields are supported.

e.g., here’s what I tried doc.getSections.get(0).getRange().getFields(), the getFields() method is not available.

Could you please let me know which version of aspose.words for java has this support?

Thanks.


#4

@vgm

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.


#5

Hi Tahir,

Thanks. Attached is the document with a sample if field.

Could you please let me know the version of Apose.words for java that has the support to evaluate such fields?
Sample FieldIf.zip (11.9 KB)


#6

@vgm

Thanks for sharing the document. Please use the following code example to achieve your requirement.

Document doc = new Document(MyDir + "Sample FieldIf.docx");

for(Field field : doc.getSections().get(0).getRange().getFields())
{
    if(field.getType() == FieldType.FIELD_IF)
    {
        System.out.println(((FieldIf)field).evaluateCondition() == FieldIfComparisonResult.TRUE);
    }
}

#7

Hi Tahir,

Thanks. I’ve tried this code. It looks like getFields() and evaluateCondition() are not supported.
Could you please provide details on the version of Aspose words(java) where these were introduced?


#8

@vgm

Thanks for your inquiry. Please use the latest version of Aspose.Words for Java 18.11.


#9

Thanks Tahir.


#10

@vgm

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