我使用 Apache POI 的 3.9 版生成 excel,并且此代码在此方面是正确的:
public CellStyle getCellStyle(XSSFWorkbook workbook){
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("###,###"));
XSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) 11);
font.setFontName("Tahoma");
cellStyle.setFont(font);
CellStyle style = workbook.createCellStyle();
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
return cellStyle;
}
Run Code Online (Sandbox Code Playgroud)
但是什么时候升级到 3.17?这些行有错误:
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
Run Code Online (Sandbox Code Playgroud)