SpringBoot项目打包提示Poi类使用了过时方法 cell.setCellType(CellType.STRING);
项目使用的poi工具类是4.1.0版本
此方法是exl导出接口 title为表头 rows是表数据
public static HSSFWorkbook exportExcel(String[] title, List<String[]> rows) {
HSSFWorkbook workbook = new HSSFWorkbook();
// 生成一个表格
HSSFSheet sheet = workbook.createSheet();
// 设置表格默认列宽度为15个字节
sheet.setDefaultColumnWidth((short) 18);
sheet.setColumnWidth(title.length - 1, (int) ((40 + 0.72) * 256));
// 循环字段名数组,创建标题行
Row row = sheet.createRow(0);
for (int j = 0; j < title.length; j++) {
// 创建列
Cell cell = row.createCell(j);
// 设置单元类型为String 方法提示过时
cell.setCellType(CellType.STRING);
cell.setCellValue(title[j]);
}
// 创建普通行
for (int i = 0; i < rows.size(); i++) {
// 因为第一行已经用于创建标题行,故从第二行开始创建
row = sheet.createRow(i + 1);
// 如果是第一行就让其为标题行
String[] rowData = rows.get(i);
for (int j = 0; j < rowData.length; j++) {
// 创建列
Cell cell = row.createCell(j);
//方法提示过时
cell.setCellType(CellType.STRING);
cell.setCellValue(rowData[j]);
}
}
return workbook;
}
能否优化过时方法
打包不再提示
优化这行代码🙄
cell.setCellType(CellType.STRING);