Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read excel fie in java using poi

I am struggling to read excel file in a dynamic web project I am developing. I could easily read it in a java application by following the same steps.

What I did?

I added these to build path

  • xmlbeans-2.6.0.jar
  • poi-3.13-20150939
  • poi-examples
  • poi-excelant
  • poi-ooxml
  • poi-ooxml-schemas
  • poi-scratchpad

Code:

FileInputStream input_document = new FileInputStream(new File("file_location"));
XSSFWorkbook my_xls_workbook = new XSSFWorkbook(input_document); 
XSSFSheet my_worksheet = my_xls_workbook.getSheetAt(0);                      
XSSFCell cell=null; 
for(int i=0;i<463;i++){
    cell = my_worksheet.getRow(i).getCell(0);
    words[i]=cell.getStringCellValue();                                                          
    System.out.println(words[i]);          
}
my_xls_workbook.close();

The Error

SEVERE: StandardWrapper.Throwable
java.lang.NoClassDefFoundError: org/apache/poi/xssf/usermodel/XSSFWorkbook

org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet vhealth.GetMed
java.lang.ClassNotFoundException: org.apache.poi.xssf.usermodel.XSSFWorkbook

It is pretty long but this is the gist of it

The Question

I want to know how to solve this and as I mentioned it works in another similar java file after following the same steps. I want to integrate it in the web app. I've also tried calling the routine which imports the database in Java from the WebApp(which uses tomcat if that helps) still no luck.

like image 321
ada2161 Avatar asked Sep 25 '22 22:09

ada2161


1 Answers

You need to add jar files not only in the build path. You need obviously to have the same files in your war module in the WEB-INF/lib folder.

P.S. I think you don't need poi-examples jar.

like image 96
v.ladynev Avatar answered Oct 11 '22 11:10

v.ladynev