java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23080945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
提问by
In order to read an xlsx
file I'm using apache POI, I've downloaded the zip and placed the following jsrs in my servlet location webcontent/web-inf/lib
and configured build path through eclipse
为了读取xlsx
我使用 apache POI的文件,我下载了 zip 并将以下 jsrs 放在我的 servlet 位置webcontent/web-inf/lib
并通过 eclipse 配置了构建路径
and my code looks as follows,
我的代码如下所示,
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;
}
}
Though this does not show and errors on eclipse it shows the following errors when I try to run the code
虽然这在 eclipse 上没有显示和错误,但当我尝试运行代码时它会显示以下错误
What is my mistake? How to solve this?
我的错误是什么?如何解决这个问题?
采纳答案by Mena
回答by Jay
Add xmlbeans-xpath.jar to your libraries.
将 xmlbeans-xpath.jar 添加到您的库中。
回答by mannedear
回答by Gregor Petrin
It looks as though you might be trying to produce Office's 2007 format with the POI version for the old formats. Use the poi-ooxml
jar for the new formats.
看起来您可能正在尝试使用旧格式的 POI 版本生成 Office 2007 格式。将poi-ooxml
jar 用于新格式。