0
package ReadExcelData;
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ReadandWriteExcel {

 public static void main(String []args){

  try {
      File src = new File("C:\\poi\\ExcelData\\TestExcelData.xlsx");
      FileInputStream fis=new FileInputStream(src);

      XSSFWorkbook wb=new XSSFWorkbook(fis);
      XSSFSheet sh1= wb.getSheetAt(0);
      System.out.println(sh1.getRow(0).getCell(0).getStringCellValue());
      System.out.println(sh1.getRow(0).getCell(1).getStringCellValue());
      System.out.println(sh1.getRow(1).getCell(0).getStringCellValue());
      System.out.println(sh1.getRow(1).getCell(1).getStringCellValue());
      System.out.println(sh1.getRow(2).getCell(0).getStringCellValue());
      System.out.println(sh1.getRow(2).getCell(1).getStringCellValue());
      wb.close();
  } catch (Exception e) {
   System.out.println(e.getMessage());
  }
 }

}

Hi,

I Downloaded poi-4.0.0 and added external jar file to my project. After setup of project I created excel file and wrote java program to read from excel file

While run time I am getting error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:298)
    at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:37)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:307)
    at ReadExcelData.ReadandWriteExcel.main(ReadandWriteExcel.java:19)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.archivers.zip.ZipFile
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more`enter code here`
3
  • Removed the selenium tag since it has nothing to do with this question. Commented Sep 25, 2018 at 0:57
  • Your Excel file is the newer format, .xlsx. Change it to the older format, .xls, and try again. Commented Sep 25, 2018 at 0:58
  • Hi JeffC,I tried but still same error. Commented Sep 25, 2018 at 2:53

1 Answer 1

3

You need to add commons-compress-1.18.jar into your project build path. https://commons.apache.org/proper/commons-compress/download_compress.cgi

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.