setCellValue 已弃用
setCellValue is deprecated
在我的项目中,我使用以下代码在 Spring 项目中添加了使用 Apache Poi 库生成 Excel 文件的功能。
public class ExcelView extends AbstractExcelView {
@Override
protected void buildExcelDocument(Map model, HSSFWorkbook workbook,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List<Employee> employees = (List) model.get("employees");
HSSFSheet sheet = workbook.createSheet("Employee Report");
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Employee Id");
header.createCell(1).setCellValue("First Name");
header.createCell(2).setCellValue("Last Name");
header.createCell(3).setCellValue("Salary");
int counter = 1;
for (Employee e : employees) {
HSSFRow row = sheet.createRow(counter++);
row.createCell(0).setCellValue(e.getEmployeeId());
row.createCell(1).setCellValue(e.getFirstName());
row.createCell(2).setCellValue(e.getLastName());
row.createCell(3).setCellValue(e.getSalary());
}
}
}
我的问题是 row.createCell(0).setCellValue();
已弃用。此方法的替代方法是什么?
改用setCellValue(new HSSFRichTextString("your string"));
或将您的 poi.jar 升级到最新版本。
在我的项目中,我使用以下代码在 Spring 项目中添加了使用 Apache Poi 库生成 Excel 文件的功能。
public class ExcelView extends AbstractExcelView {
@Override
protected void buildExcelDocument(Map model, HSSFWorkbook workbook,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List<Employee> employees = (List) model.get("employees");
HSSFSheet sheet = workbook.createSheet("Employee Report");
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Employee Id");
header.createCell(1).setCellValue("First Name");
header.createCell(2).setCellValue("Last Name");
header.createCell(3).setCellValue("Salary");
int counter = 1;
for (Employee e : employees) {
HSSFRow row = sheet.createRow(counter++);
row.createCell(0).setCellValue(e.getEmployeeId());
row.createCell(1).setCellValue(e.getFirstName());
row.createCell(2).setCellValue(e.getLastName());
row.createCell(3).setCellValue(e.getSalary());
}
}
}
我的问题是 row.createCell(0).setCellValue();
已弃用。此方法的替代方法是什么?
改用setCellValue(new HSSFRichTextString("your string"));
或将您的 poi.jar 升级到最新版本。