java.lang.ClassNotFoundException:org.apache.xmlbeans.XmlException
为了读取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); Iterator row = 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-xxxjar
将xmlbeans-xpath.jar添加到库中。
我已经下载了最新的poi-3.17二进制文件,xmlbeans-xxxjar包含在下载的软件包中。
附上截图FYR。
- 通过XSSFRichTexString和Jsoup进行Apache POI Excel文本格式化
- java使用APACHE POI在powerpoint中创建图表
- 如何将.docx的段落复制到另一个.docx withJava并保留样式
- Java中的Word文档创建API
- 获取单元格值,以及它在excel中的显示方式
- FileInputStream vs ClassPathResource vs getResourceAsStream和文件完整性
- 如何使用poi jar读取java api中的docx文件内容
- Apache POI解析错误
- 在LibreOffice中不会自动调整Apache poi Excel行高