Java 无法获取Apache POI以使我的Excel读取正常工作

Java 无法获取Apache POI以使我的Excel读取正常工作,java,excel,apache-poi,deprecation-warning,Java,Excel,Apache Poi,Deprecation Warning,我正在尝试使用这个基本布局的程序,可以读取Excel文件。我想扩展到此代码之外的内容,但由于某些原因,每次构建代码时,我都会遇到一个错误“注意:C:\Users\Ryan Kabir\Documents\NetBeansProjects\ExcelReader\src\ExcelReader\ExcelReader.java使用或覆盖不推荐使用的API。 注意:请使用-Xlint:deprecation重新编译以了解详细信息。“我尝试使用javac-Xlint:deprecation Excel

我正在尝试使用这个基本布局的程序,可以读取Excel文件。我想扩展到此代码之外的内容,但由于某些原因,每次构建代码时,我都会遇到一个错误“注意:C:\Users\Ryan Kabir\Documents\NetBeansProjects\ExcelReader\src\ExcelReader\ExcelReader.java使用或覆盖不推荐使用的API。 注意:请使用-Xlint:deprecation重新编译以了解详细信息。“我尝试使用javac-Xlint:deprecation ExcelReader.java进行编译,但我无法找到不推荐使用的方法。 对不对,我的测试excel文件只是一个3x6表

导入java.io.File;
导入java.io.FileInputStream;
导入java.io.IOException;
导入java.util.Iterator;
导入org.apache.poi.ss.usermodel.Cell;
导入org.apache.poi.ss.usermodel.Row;
导入org.apache.poi.ss.usermodel.Sheet;
导入org.apache.poi.ss.usermodel.工作簿;
导入org.apache.poi.xssf.usermodel.xssf工作簿;
/**
*读取Excel文件的简单程序。
*@author www.codejava.net
*
*/
公共课优秀读者{
公共静态void main(字符串[]args)引发IOException{
字符串excelFilePath=“Books.xlsx”;
FileInputStream inputStream=新FileInputStream(新文件(excelFilePath));
工作簿=新XSSF工作簿(inputStream);
Sheet firstSheet=工作簿。getSheetAt(0);
迭代器迭代器=firstSheet.Iterator();
while(iterator.hasNext()){
行nextRow=iterator.next();
迭代器cellIterator=nextRow.cellIterator();
while(cellIterator.hasNext()){
Cell=cellIterator.next();
开关(cell.getCellType()){
case Cell.Cell\u类型\u字符串:
System.out.print(cell.getStringCellValue());
打破
case Cell.Cell\u类型\u布尔值:
System.out.print(cell.getBooleanCellValue());
打破
case Cell.Cell\u类型\u数值:
System.out.print(cell.getNumericCellValue());
打破
}
系统输出打印(“-”);
}
System.out.println();
}
workbook.close();
inputStream.close();
}
}
中的以及中的所有字段都已弃用。请使用和,如中所示

它需要稍微改变一下,因为

error: an enum switch case label must be the unqualified name of an enumeration constant
     case CellType.STRING:
但以下措施应该奏效:

import org.apache.poi.ss.usermodel.CellType;
...
            switch (cell.getCellTypeEnum()) { //up to apache poi version 3.17
            //switch (cell.getCellType()) { //using apache poi version 4.0.0 upwards

                case STRING:
                    System.out.println(cell.getRichStringCellValue().getString());
                    break;
                case NUMERIC:
                    if (DateUtil.isCellDateFormatted(cell)) {
                        System.out.println(cell.getDateCellValue());
                    } else {
                        System.out.println(cell.getNumericCellValue());
                    }
                    break;
                case BOOLEAN:
                    System.out.println(cell.getBooleanCellValue());
                    break;
                case FORMULA:
                    System.out.println(cell.getCellFormula());
                    break;
                case BLANK:
                    System.out.println();
                    break;
                default:
                    System.out.println();
            }
...
读报纸总是好的



现在,从
apachepoi
version
4.0.0
向上返回。所以使用这些版本,我们现在就需要使用这种方法。

您使用的是什么版本的
apachepoi
?张贴您的家属这不是错误,而是警告。这不是不起作用的原因,您没有具体说明。