为了读取xlsx
我正在使用apache POI 的文件,我已经下载了zip并将以下jsrs放在我的servlet位置webcontent/web-inf/lib
并通过eclipse配置了构建路径
我的代码如下,
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; File uploadedFile = new File(fpath, fileName); item.write(uploadedFile); String mimeType = (Files.probeContentType(uploadedFile.toPath())).toString(); System.out.println(mimeType); if(mimeType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { FileInputStream file = new FileInputStream(uploadedFile); XSSFWorkbook workbook = new XSSFWorkbook(file); for (int i =0; i < workbook.getNumberOfSheets(); i++) { XSSFSheet sheet = workbook.getSheetAt(i); Iteratorrow = sheet.iterator(); while(row.hasNext()) { Iterator
cellIterator = ((Row) row).cellIterator(); while(cellIterator.hasNext()) { Cell cell1 = cellIterator.next(); switch(cell1.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: System.out.print(cell1.getBooleanCellValue() + "\n"); break; case Cell.CELL_TYPE_NUMERIC: System.out.print(cell1.getNumericCellValue() + "\n"); break; case Cell.CELL_TYPE_STRING: System.out.print(cell1.getStringCellValue() + "\n"); break; } } |
虽然这在eclipse上没有显示和错误,但在我尝试运行代码时会显示以下错误
我的错是什么?怎么解决这个?
您需要将XML bean依赖项添加到类路径中.
通常会调用该库 xmlbeans-x.x.x.jar
我已经下载了最新的poi-3.17二进制文件,并且xmlbeans-xxxjar包含在下载的程序包中。
附上截图FYR。