Reputation: 43
I am trying to read xlsx file to get data form file but my code generate en eroor like this
apache poi is not working or help to read xlsx file
any can tell what i need to do solve this error
or other way to read xlsx file in java
Exception in thread "main" java.lang.IllegalStateException: Zip File is closed
at org.apache.poi.openxml4j.util.ZipFileZipEntrySource.getEntries(ZipFileZipEntrySource.java:45)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:161)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:662)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:223)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:186)
at ExampleEventUserModel.processOneSheet(ExampleEventUserModel.java:18)
at ExampleEventUserModel.main(ExampleEventUserModel.java:115)
Upvotes: 1
Views: 9571
Reputation: 309
I faced a similar issue and fixed it by giving the absolute path instead of just file name.
Instead of giving
OPCPackage pkg = OPCPackage.open(filename);
You can give
OPCPackage pkg = OPCPackage.open(absolutePath + "/" + filename);
Upvotes: 6
Reputation: 1210
If you want to read xlsx file. We must use
XSSFWorkbook workBook = new XSSFWorkbook(inputStream);
Upvotes: 1