Search code examples
docx4j

docx4j simulate expression evaluation


I have a docx document with some formulas, e.g.

{IF "Name" = "Foo" "Foo" "Bar"}

which should print "Bar" at the end.

In Word I have to press "F9" to get the expression evaluated. No I am using docx4j, can I somehow tell docx4j to do the evaluation?


Solution

  • I'm afraid not. You can get the expression of course (see this discussion about some classes which help), but there is currently nothing in docx4j to evaluate an IF field for you.

    If the objective is to include/exclude text, you'll be able to achieve the same end with an OpenDoPE conditional content control (based on whether an XPath evaluates to true or false). (docx4j can evaluate these; they can also be nested, to support complex content)