Apache Commons JEXL Expressions

JETT leverages Apache Commons JEXL to evaluate JEXL ("Java Expression Language") Expressions contained in the template spreadsheet. JETT interprets everything between "${" and "}" to be a JEXL Expression. The JEXL Expression is evaluated as the result of getting the property "property" from the bean "beanName", which is retrieved from the bean Map with the key "beanName". JETT replaces the Expression with the result of the evaluation. JETT will also evaluate expressions found in the sheet name and in the sheet header and footer.

In this example, a ValueObject is a JETT user's own type, not a JETT built-in type.

Map<String, Object> beans = new HashMap<String, Object>();
ValueObject beanName = new ValueObject();
beanName.setProperty("Hello, World!");
beans.put("beanName", beanName);

If the template spreadsheet contains this cell...


...then it gets transformed into...

Hello, World!

Complex Expressions

Bean property accesses may be chained to any desired length. All Excel formatting is preserved, including Rich Text formatting, normal font formatting, number and date formatting, text color, cell background, cell alignments, cell borders, column widths, row heights, text wrapping, and merged cell regions. Features such as drawings, charts, and macros are preserved as much as possible. JEXL supports a rich expression language that includes array access, list access, map access, math operators, comparison operators, explicit method calling, and more.

${n}^2 is ${n * n} ${country.state.county.city.name}, ${country.state.code} ${change * 100}%

...gets transformed into...

5^2 is 25 Los Angeles, CA 25.00%

It is also possible to register functions in custom namespaces, to reference custom functions within JEXL.

Static Methods

JETT extends JEXL to allow references to static methods directly in JEXL Expressions. Supply the fully-qualified class name. For example, if the bean "methodType" is the value "Static", then the template...

${java.lang.String.format('%s methods are allowed!', methodType)}

... gets transformed into...

Static methods are allowed!