Skip to content

jx:mergeCells

jx:mergeCells merges cells in a rectangular range during template processing. This is essential when you need section headers that span multiple columns inside a loop.

jx:mergeCells(lastCell="C1" cols="3" rows="1")
AttributeDescriptionRequired
lastCellBottom-right cell of the command areaYes
colsNumber of columns to mergeYes
rowsNumber of rows to mergeYes

You can merge cells in your template file directly — and for static headers, you should. But when merges happen inside a loop (like a department header that spans 3 columns, repeated for each department), you need jx:mergeCells because the merge positions change with each iteration.

A department report with a merged header per department:

Cell A1 comment:
jx:area(lastCell="C5")
jx:each(items="departments" var="dept" lastCell="C5")
Cell A1 also has:
jx:mergeCells(lastCell="C1" cols="3" rows="1")

Cell A1 value: ${dept.Name}

For each department, the department name cell spans columns A through C, creating a clean section header.

Download the runnable example: template t11.xlsx | output 11_mergecells.xlsx | code snippet

Need to set a summary or total cell?

jx:updateCell →