Skip to main content

Posts

Showing posts with the label HSSF

Java : Read from Excel (xls) file

Reading from a text file is common. But, reading from an excel(.xls) file is not. Recently, I got to do so. Little bit Google search and experimentation resulted in the following. I used HSSF from Apache-POI. import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; public void readFromXlsFile (String pathToFile, String sheetName){     try {         FileInputStream file = new FileInputStream(pathToFile);         HSSFWorkbook workbook = new HSSFWorkbook(file);         HSSFSheet sheet = workbook.getSheet(sheetName);         Iterator<Row> rowIterator = sheet.rowIterator();                     while (rowIterator.hasNext()) {  ...