低版本升级高版本
1.1 颜色定义变化
旧:
setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index)
cellStyle.setBottomBorderColor(HSSFColor.BLACK.getIndex());
cellStyle.setTopBorderColor(HSSFColor.BLACK.getIndex());
新:
setFillForegroundColor(IndexedColors.SKY_BLUE.index)
setBottomBorderColor(IndexedColors.BLACK.getIndex());
setTopBorderColor(IndexedColors.BLACK.getIndex());
1.2 获取单元格格式
旧:
cell.getCellType() < 2
CELL_TYPE_NUMERIC =0
CELL_TYPE_STRING = 1
CELL_TYPE_FORMULA = 2
Cell.CELL_TYPE_NUMERIC
新:
cell.getCellTypeEnum().NUMERIC == CellType.NUMERIC || cell.getCellTypeEnum().NUMERIC == CellType.STRING
CellType.NUMERIC
1.3 设置单元格格式
旧 :
row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
新 :
row.getCell(0).setCellType(CellType.STRING);
1.4 设置单元格垂直居中样式
旧:
setAlignment(XSSFCellStyle.ALIGN_CENTER); // 居中
setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);//垂直
新:
setAlignment(HorizontalAlignment.CENTER); // 居中
setVerticalAlignment(VerticalAlignment.CENTER); //垂直
1.5 设置边框
旧:
setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
setBorderLeft(HSSFCellStyle.BORDER_THIN);
setBorderRight(HSSFCellStyle.BORDER_THIN);
setBorderTop(HSSFCellStyle.BORDER_THIN);
新:
setBorderBottom(BorderStyle.THIN); //下边框
setBorderLeft(BorderStyle.THIN);
setBorderRight(BorderStyle.THIN);
setBorderTop(BorderStyle.THIN);
1.6 合并单元格
旧:
addMergedRegion(new CellRangeAddress(1, 1,(short) 0, (short) 0));// 起始行,结束行,起始列,结束列
新:
addMergedRegion(new Region(1, (short) 0, 1,(short) 0));// 起始行,起始列,结束行,结束列
1.7 设置字体加粗
旧
setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
新:
setBold(true)
1.8 字体颜色
旧:
setColor(HSSFColor.BLACK.index)
新:
setColor(IndexedColors.BLACK.getIndex())
1.9设置样式
旧:
setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
新:
setFillPattern(FillPatternType.SOLID_FOREGROUND);
setFillForegroundColor(IndexedColors.SKY_BLUE.index);