user3053980
user3053980

Reputation: 1

Java program reading data from a excel file throws and error..need help to resolve

I'm using XSSF user model to read data in excel file and print them. I have added all POI Jar files in to Java Build Path --> Libraries. But still i'm getting same error. Please help me to resolve this issue. package com.javalab.sample;

import java.io.*;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class ReadFromExcel3 {

public static void main(String[] args)  {
try {

File excel1 = new File ("C:\\TestData\\test.xlsx");
FileInputStream fis1 = new FileInputStream(excel1);

XSSFWorkbook xssfWork = new XSSFWorkbook(fis1);
XSSFSheet sheet1 = xssfWork.getSheetAt(0);
Iterator<Row> rowItr = sheet1.rowIterator();

while ( rowItr.hasNext() ) 
{
    XSSFRow row = (XSSFRow) rowItr.next();
    System.out.println("ROW:-->");
    Iterator<Cell> cellItr = row.cellIterator();

    while ( cellItr.hasNext() ) 
    {
        XSSFCell cell = (XSSFCell) cellItr.next();
        System.out.println("CELL:-->"+cell.toString());
    }
}
} 

catch (Exception e) 
{
   e.printStackTrace();
}

}
}

Exception

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/xmlbeans/XmlException
at com.javalab.sample.ReadFromExcel3.main(ReadFromExcel3.java:22)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 1 more

Upvotes: 0

Views: 916

Answers (1)

JB Nizet
JB Nizet

Reputation: 691635

You forgot to add the xmlbeans-xxx.jar coming with the POI binary distribution (under ooxml-lib) in your classpath.

Upvotes: 1

Related Questions