Skip to content

jx:if

jx:if conditionally includes or excludes a template area based on a boolean expression. Think of it as an if statement for your spreadsheet layout.

jx:if(condition="e.Active" lastCell="C1")
AttributeDescriptionRequired
conditionBoolean expressionYes
lastCellBottom-right cell of the conditional areaYes
ifAreaArea ref to render when true (advanced)No
elseAreaArea ref to render when false (advanced)No

When the condition is true, the area is rendered. When false, it’s omitted and subsequent rows shift up to fill the gap.

Template:

Template with jx:if condition that controls whether a row appears

Output (condition true):

Output showing the conditional area rendered because the condition was true

The most common pattern — show something only when a condition is met:

Template:

Template with jx:if and no else area

Output:

Output with the conditional area omitted for false conditions

When the condition is false, the area simply disappears and rows below shift up.

jx:if is powerful when combined with jx:each. Only show rows for items matching a condition:

Cell A1 comment:
jx:area(lastCell="C2")
jx:each(items="employees" var="e" lastCell="C2")
Cell A2 comment:
jx:if(condition="e.Active" lastCell="C2")

Only active employees appear in the output.

Any expression returning a boolean works:

jx:if(condition="e.Age >= 18 && e.Department == 'Engineering'" lastCell="C1")
jx:if(condition="len(items) > 0" lastCell="D5")

For more advanced control, render different template regions depending on the condition:

jx:if(condition="hasData" ifArea="A2:C5" elseArea="A7:C8" lastCell="C8")

When hasData is true, the A2:C5 region is rendered. When false, A7:C8 is rendered instead. This lets you show a data table or a “no results” message from the same template.

Download the runnable example: template t07.xlsx | output 07_if_command.xlsx | code snippet

Need to fill a dynamic grid with headers and data rows?

jx:grid →