0% found this document useful (0 votes)
17 views1 page

Untitled

Uploaded by

singnikhil
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Untitled

Uploaded by

singnikhil
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package mypkg; import java.io.FileInputStream; import java.util.ArrayList; import java.util.Iterator; import import import import import org.apache.poi.hssf.usermodel.HSSFCell; org.apache.poi.hssf.usermodel.

HSSFRow; org.apache.poi.hssf.usermodel.HSSFSheet; org.apache.poi.hssf.usermodel.HSSFWorkbook; org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class ReadExcelFile { public ArrayList<ArrayList<String>> readFile(String fileName) { ArrayList<ArrayList<String>> cellVectorHolder = new Arra yList<ArrayList<String>>(); try { FileInputStream myInput = new FileInputStream(fileName); POIFSFileSystem myFileSystem = new POIFSFileSystem(myInp ut); HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem) ; HSSFSheet mySheet = myWorkBook.getSheetAt(0); Iterator rowIter = mySheet.rowIterator(); while (rowIter.hasNext()) { HSSFRow myRow = (HSSFRow) rowIter.next(); Iterator cellIter = myRow.cellIterator(); ArrayList<String> cellStoreVector = new ArrayLis t<String>(); while (cellIter.hasNext()) { HSSFCell myCell = (HSSFCell) cellIter.ne xt(); cellStoreVector.add(myCell.toString()); } cellVectorHolder.add(cellStoreVector); } } catch (Exception e) { e.printStackTrace(); } return cellVectorHolder; } }

You might also like