java.lang.ClassNotFoundException:org.apache.xmlbeans.xmleException
为了读取我正在使用ApachePOI的java.lang.ClassNotFoundException:org.apache.xmlbeans.xmleException,java,apache-poi,Java,Apache Poi,为了读取我正在使用ApachePOI的xlsx文件,我下载了zip并将以下JSR放置在我的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.apach
xlsx
文件,我下载了zip并将以下JSR放置在我的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> row = sheet.iterator();
while(row.hasNext()) {
Iterator<Cell> 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;
}
}
import org.apache.poi.ss.usermodel.Cell;
导入org.apache.poi.ss.usermodel.Row;
导入org.apache.poi.xssf.usermodel.xssfheet;
导入org.apache.poi.xssf.usermodel.xssf工作簿;
文件上传文件=新文件(fpath,文件名);
item.write(上传文件);
字符串mimeType=(Files.probeContentType(uploadedFile.toPath()).toString();
System.out.println(mimeType);
if(mimeType.equals(“application/vnd.openxmlformats officedocument.spreadsheetml.sheet”))
{
FileInputStream文件=新的FileInputStream(uploadedFile);
XSSF工作簿=新XSSF工作簿(文件);
对于(int i=0;i
虽然这不会在eclipse上显示错误,但在我尝试运行代码时会显示以下错误
我的错误是什么?如何解决这个问题?您需要将依赖项添加到类路径中
该库通常称为
xmlbeans-x.x.x.jar
将xmlbeans-xpath.jar添加到您的库中。我已经下载了最新的poi-3.17二进制文件,xmlbeans-x.x.jar包含在下载的包中
附上截图供参考
看起来您可能正试图用POI版本为旧格式生成Office的2007格式。使用
POI ooxml
jar为新格式。好的。但是如何在eclipse中添加它?手动:获取jar,转到项目,属性,Java构建路径,添加外部jar并选择.jar文件。我有一个Swing应用程序正在运行很好,在Windows上读取Excel文件,但在我的Linux虚拟机上,我得到了java.lang.ClassNotFoundException:org.apache.xmlbeans.xmleexception???包含xmlbeans jar。