I've tried to apply apache poi
but failed. I have been searching around to find the solution, yet still cannot solve the problem. Not sure whether is java version not compatible or missing jar file. I need a guidance from a professional.
我尝试过应用apache poi,但失败了。我一直在寻找解决方案,但仍然无法解决问题。不确定是否是java版本不兼容或缺少jar文件。我需要专业人士的指导。
Current version after system.out : 1.6.0 System.out.println(Runtime.class.getPackage().getImplementationVersion());
当前版本后系统。:1.6.0 System.out.println(Runtime.class.getPackage().getImplementationVersion());
External Jar file added:
- dom4j-1.6.1.jar
- log4j-1.2.17.jar
- junit-4.11.jar
- poi-3.11-20141211.jar
- poi-ooxml-3.11-20141211.jar
- poi-ooxml-schemas-3.11-20141211.jar
- xmlbeans-2.6.0.jar
外部Jar文件添加:- dom4j-1.6.1。jar——log4j-1.2.17。jar——junit 4.11。jar - poi - 3.11 - 20141211。jar——poi ooxml - 3.11 - 20141211。jar——poi ooxml -模式- 3.11 - 20141211。jar——xmlbeans-2.6.0.jar
JSP FILE
//jsp is my front end system
<jsp:useBean id="ReadXLSXFile" scope="page" class="com.home.file.ReadXLSXFile" />
<script>
if(sType.equals("Y"))
{
ReadXLSXFile.main(null);
}
</script>
Java file
package com.home.file;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
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;
public class ReadXLSXFile {
public static void main(String[] args) {
try {
File excel = new File("C:/Banklist.xlsx");
FileInputStream fis = new FileInputStream(excel);
XSSFWorkbook book = new XSSFWorkbook(fis);
XSSFSheet sheet = book.getSheetAt(0);
Iterator<Row> itr = sheet.iterator();
// Iterating over Excel file in Java
while (itr.hasNext()) {
Row row = itr.next();
// Iterating over each column of Excel file
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.err.print(cell.getStringCellValue() + "\t");
break;
case Cell.CELL_TYPE_NUMERIC:
System.err.print(cell.getNumericCellValue() + "\t");
break;
case Cell.CELL_TYPE_BOOLEAN:
System.err.print(cell.getBooleanCellValue() + "\t");
break;
default:
}
}
System.err.println("");
}
} catch (FileNotFoundException fe) {
fe.printStackTrace();
} catch (IOException ie) {
ie.printStackTrace();
}
}
}
error is shown after read the excel file.xlsx
读取excel文件.xlsx后显示错误。
Eclipse console result :
Eclipse控制台的结果:
Caused by: java.lang.NoClassDefFoundError: org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller (initialization failure)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:140)
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:87)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:272)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:258)
at com.rexit.easc.ReadXLSXFile.main(ReadXLSXFile.java:26)
at com.ibm._jsp._pop_5F_cnFW_5F_nstbl._jspService(_pop_5F_cnFW_5F_nstbl.java:500)
P/s : the question is quite similar with this thread, but I still cannot figure it out. Here
P/s:这个问题和这个问题很相似,但我还是搞不懂。在这里
2 个解决方案
#1
1
org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller is missing in poi-3.11-20141211.jar.
First, you can check ZipPackagePropertiesMarshaller class is have in this jar.
If not have, may be your poi-3.11-20141211.jar is invalid or poi-3.11-20141211.jar is not supported for ZipPackagePropertiesMarshaller.
在poi-3.11-20141211.jar中丢失了zippackagepropertiesmarshaller。首先,您可以检查这个jar中的ZipPackagePropertiesMarshaller类。如果没有,可能是你的poi-3.11-20141211。jar无效或poi-3.11-20141211。jar不支持ZipPackagePropertiesMarshaller。
I would recommend you to change poi-ooxml-3.11-20141211.jar to poi-ooxml-3.9-20121203.jar.
#2
-1
use the jdk version 1.6.20 or higher to work with XSSFWorkbook. your jdk version should be higher than 1.6.20
使用jdk 1.6.20或更高版本使用XSSFWorkbook。您的jdk版本应该高于1.6.20。
#1
1
org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller is missing in poi-3.11-20141211.jar.
First, you can check ZipPackagePropertiesMarshaller class is have in this jar.
If not have, may be your poi-3.11-20141211.jar is invalid or poi-3.11-20141211.jar is not supported for ZipPackagePropertiesMarshaller.
在poi-3.11-20141211.jar中丢失了zippackagepropertiesmarshaller。首先,您可以检查这个jar中的ZipPackagePropertiesMarshaller类。如果没有,可能是你的poi-3.11-20141211。jar无效或poi-3.11-20141211。jar不支持ZipPackagePropertiesMarshaller。
I would recommend you to change poi-ooxml-3.11-20141211.jar to poi-ooxml-3.9-20121203.jar.
#2
-1
use the jdk version 1.6.20 or higher to work with XSSFWorkbook. your jdk version should be higher than 1.6.20
使用jdk 1.6.20或更高版本使用XSSFWorkbook。您的jdk版本应该高于1.6.20。