// Create an xlsx file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("AutoMerge.xlsx"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Create a new workbook Workbook workbook = new Workbook(); InputStream fileStream = this.getResourceStream("xlsx/Regional_Product_List.xlsx"); workbook.open(fileStream); IWorksheet worksheet = workbook.getActiveSheet(); //Add auto merge range with restricted mode and merged selection mode. worksheet.autoMerge(worksheet.getUsedRange(), AutoMergeDirection.Column, AutoMergeMode.Restricted, AutoMergeSelectionMode.Merged); //The IncludeAutoMergedCells is true, the automatically merged cells will become normal merged cells in excel. XlsxSaveOptions options = new XlsxSaveOptions(); options.setIncludeAutoMergedCells(true); workbook.save(outputStream, options); // Close the xlsx stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }