import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import org.apache.poi.hssf.usermodel.HSSFOptimiser; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellReference; import static org.apache.poi.ss.usermodel.BorderStyle.THIN; public class Issue { public static void main(String[] args) throws IOException { try (OutputStream out = Files.newOutputStream(Path.of("report.xls"))) { new Issue().generateReport().write(out); } } public Workbook generateReport() { HSSFWorkbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("styles"); for (int i = 0; i < 4; i++) { Row row = sheet.createRow(i); for (int j = 0; j < 11; j++) { Cell cell = row.createCell(j); cell.setCellStyle(createDefaultStyle(wb)); cell.setCellValue(CellReference.convertNumToColString(j) + (i + 1)); } } // workaround 1 // HSSFOptimiser.optimiseCellStyles(wb); return wb; } private CellStyle createDefaultStyle(Workbook wb) { CellStyle style = wb.createCellStyle(); style.setBorderTop(THIN); style.setBorderBottom(THIN); style.setBorderLeft(THIN); style.setBorderRight(THIN); // workaround 2 // style.setFont(wb.createFont()); return style; } }