在我的項目中,我使用下面的代碼添加了在Spring項目中使用Apache Poi庫生成Excel文件的功能。setCellValue已棄用
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();
已被棄用。什麼是替代這種方法?
我想你正在調用'createCell(short columnIndex)'這是棄用,而不是你需要調用'createCell(int column)'。 – Prashant
您是否嘗試升級到最新版本的Apache POI,目前是3.12? – Gagravarr