在Java中读取Excel工作表时出现NoSuchFieldError

我遵循了使用Apache POI

XSSF构造工作簿的简单指南。遵循相同的指南,我能够写出一张Excel工作表,但是,当尝试从其中读取数据时,我收到了代码后显示的错误。

码:

try {

FileInputStream file = new FileInputStream(new File("howtodoinjava_demo.xlsx"));

// Create Workbook instance holding reference to .xlsx file

XSSFWorkbook workbook = new XSSFWorkbook(file);

// Get first/desired sheet from the workbook

XSSFSheet sheet = workbook.getSheetAt(0);

// Iterate through each rows one by one

Iterator<Row> rowIterator = sheet.iterator();

while (rowIterator.hasNext()) {

Row row = rowIterator.next();

// For each row, iterate through all the columns

Iterator<Cell> cellIterator = row.cellIterator();

while (cellIterator.hasNext()) {

Cell cell = cellIterator.next();

// Check the cell type and format accordingly

switch (cell.getCellType()) {

case Cell.CELL_TYPE_NUMERIC:

System.out.print(cell.getNumericCellValue() + "t");

break;

case Cell.CELL_TYPE_STRING:

System.out.print(cell.getStringCellValue() + "t");

break;

}

}

System.out.println("");

}

file.close();

} catch (Exception e) {

e.printStackTrace();

}

错误输出:

线程“主”中的异常java.lang.NoSuchFieldError:org.apache.poi.openxml4j.opc.internal.ZipHelper.verifyZipHeader(ZipHelper.java:179)处的RAW_XML_FILE_HEADER

org.apache.poi.openxml4j.opc.internal.ZipHelper处的org.apache.poi.openxml4j.opc.ZipPackage。(ZipPackage.java:93)的.openZipStream(ZipHelper.java:228)org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:294)的.openZipStream(ZipHelper.java:228)在org.apache.poi.xssf.usermodel.XSSFWorkbook。(XSSFWorkbook.java:273)在org.apache.poi.xssf.usermodel.XSSFWorkbook。(XSSFWorkbook.java:273)在com.wtolliver.spring.test.ReadExcel。

com.wtolliver.spring.test.App.main上的readExcel(ReadExcel.java:18)(App.java:17)

回答:

环顾四周后。我浏览了有关APACHE

POI的文档,发现这是常量之一(不是我知道这实际上意味着什么)。

但是最终,我意识到我使用的所有教程都是2014年以前的。

所以我只是将Maven POM更改为3.11版,同时具有apache-poi和的依赖关系poi-ooxml

现在正在工作。

以上是 在Java中读取Excel工作表时出现NoSuchFieldError 的全部内容, 来源链接: utcz.com/qa/422461.html

回到顶部