Merging Cells in Excel Using POI

Merging Cells in Excel using POI can be done using the XSSFSheet.addMergedRegion(CellRangeAddress region) method.
CellRangeAddress is the range of the rows and columns that need to be selected. In our case to be merged. The constructor of CellRangeAddress takes 4 params – CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol)

Lets see example on how we can merge cells in excel file

Output

Merging Cells in Excel Using POI