Setting the borders, the border of the right side is not being rendered. I develop a pice of code for easy test: public Workbook createWorkBook() { Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("new sheet"); Row row = sheet.createRow((short) 1); Cell cell = row.createCell((short) 1); cell.setCellValue("This is a test of merging"); sheet.addMergedRegion(new CellRangeAddress( 1, //first row (0-based) 1, //last row (0-based) 1, //first column (0-based) 2 //last column (0-based) )); // Style the cell with borders all around. CellStyle style = wb.createCellStyle(); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); cell.setCellStyle(style); return wb; }
Note: * I set the Left, Right, and Bottom, but the Right border is not being rendered with BORDER_THIN + BLACK. * I forgot to remove the comment: // Style the cell with borders all around. It can generate mistakes.
I just tried it, it will work if you set the same style on the second cell as well: cell = row.createCell(2); cell.setCellStyle(style); I am not sure if this is expected behavior or something that should be changed in POI, but at least you can use this as workaround for now.