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.
Syntax
Section titled “Syntax”jx:mergeCells(lastCell="C1" cols="3" rows="1")Attributes
Section titled “Attributes”| Attribute | Description | Required |
|---|---|---|
lastCell | Bottom-right cell of the command area | Yes |
cols | Number of columns to merge | Yes |
rows | Number of rows to merge | Yes |
Why you need this
Section titled “Why you need this”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.
Example
Section titled “Example”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.
Try it
Section titled “Try it”Download the runnable example: template t11.xlsx | output 11_mergecells.xlsx | code snippet
Next command
Section titled “Next command”Need to set a summary or total cell?