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
为了读取使用apache POI的xlsx文件,我下载了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?
我的错误是什么?如何解决呢?
3 个解决方案
#1
29
You need to add the XML beans dependency to your class path.
您需要将XML bean依赖项添加到类路径中。
The library is usually called xmlbeans-x.x.x.jar
这个库通常称为xmlbeans-x.x. jar
#2
3
Add xmlbeans-xpath.jar to your libraries.
添加xmlbeans-xpath。jar库。
#3
#1
29
You need to add the XML beans dependency to your class path.
您需要将XML bean依赖项添加到类路径中。
The library is usually called xmlbeans-x.x.x.jar
这个库通常称为xmlbeans-x.x. jar
#2
3
Add xmlbeans-xpath.jar to your libraries.
添加xmlbeans-xpath。jar库。