Java setCellValue已弃用

Java setCellValue已弃用,java,excel,apache-poi,Java,Excel,Apache Poi,在我的项目中,我使用下面的代码,在Spring项目中添加了使用ApachePOI库生成Excel文件的功能 public class ExcelView extends AbstractExcelView { @Override protected void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse re

在我的项目中,我使用下面的代码,在Spring项目中添加了使用ApachePOI库生成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());
      }
     }
}
公共类ExcelView扩展了AbstractExcelView{
@凌驾
受保护的无效文件(地图模型、HSSF工作簿、,
HttpServletRequest请求,HttpServletResponse响应)
抛出异常{
List employees=(List)model.get(“employees”);
HSSFSheet sheet=工作簿.createSheet(“员工报告”);
HSSFRow表头=sheet.createRow(0);
header.createCell(0.setCellValue(“员工Id”);
header.createCell(1.setCellValue(“名字”);
header.createCell(2.setCellValue(“姓氏”);
header.createCell(3.setCellValue(“工资”);
int计数器=1;
对于(员工e:员工){
HSSFRow行=sheet.createRow(计数器++);
createCell(0).setCellValue(e.getEmployeeId());
createCell(1).setCellValue(e.getFirstName());
createCell(2).setCellValue(e.getLastName());
createCell(3).setCellValue(e.getSalary());
}
}
}
我的问题是
row.createCell(0.setCellValue()已弃用。此方法的替代品是什么?

使用
setCellValue(新的HSSFRichTextString(“您的字符串”)取而代之


或者将您的poi.jar升级到最新版本。

我想您正在调用
createCell(short columnIndex)
这是不推荐使用的,您需要调用
createCell(int column)
。您是否尝试升级到Apache poi的最新版本,目前为3.12?@Prashant您的解决方案对我有效,只是更改了createCell(short columnIndex)到createCell(int column)谢谢,@Howard,它删除了我的警告消息。我使用了最新的poi-3.4 final JAR。我认为poi javadoc和代码不同步。官方javadoc不反对setCellValue(字符串)网站上的POI javadocs总是指最新版本。对于历史上的javadocs,您需要使用与下载捆绑在一起的javadocs作为您正在使用的版本