Need to read data
from excel sheet:
We can use Apache
POI API, to access the Microsoft documents including Excel formats.
Refer below page
for more information on XL API
Need Apache POI
jar files:
- poi-3.1-FINAL-20080629.jar
- poi-scratchpad-3.1-FINAL-20080629.jar
- poi-contrib-3.1-FINAL-20080629.jar
- poi-2.5.1-final-20080629.jar
If we need to read
from from xslx then we have to use POI 3.7 version.
Here is the sample
code:
if(upload.getContentType().equalIgnoreCase("application/vnd.ms-excel") || ( upload.getContentType().equalIgnoreCase("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { Vector cellVectHolder = new Vector(); Iterator rowIter = null; try{ Workbook wb = WorkbookFactory.create(upload.getInputStream); Sheet mySheet = wb.getSheetAt(0); rowIter = mySheet.rowIterator(); while(rowIter.hasNext()){ Row myRow = (Row) rowIter.next(); Iterator cellIter = myRow.cellIterator(); Vector cellStoreVect = new Vector(); while(cellIter.hasNext()){ Cell myCell = (Cell) cellIter.next(); cellStoreVect.addElement(myCell); } cellVectHolder.addElement(cellStoreVect); } for(int i=0;i i<cellVectHolder.size();i++) { Vector cellStoreVect = (Vector)cellVectHolder.elementAt(i); for(int j=0; j<cellStoreVect.size();j++) { Cell myCell = (Cell) cellStoreVect.elementAt(j); String stringCellValue = mycell.toString(); System.out.println("stringCellValue" +stringCellValue); } System.out.println(); } } catch(Exception e) { e.printStackTrace(); }