Example usage for org.apache.poi.hssf.usermodel HSSFSheet rowIterator

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet rowIterator

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFSheet rowIterator.

Prototype

@Override
public Iterator<Row> rowIterator() 

Source Link

Usage

From source file:utils.ReadWriteExcelFile.java

public static void readXLSFile(String aFile) throws IOException {
    InputStream ExcelFileToRead = new FileInputStream(aFile);
    HSSFWorkbook wb = new HSSFWorkbook(ExcelFileToRead);

    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFRow row;//w w  w  .ja  v  a 2  s.  co  m
    HSSFCell cell;

    Iterator rows = sheet.rowIterator();

    while (rows.hasNext()) {
        row = (HSSFRow) rows.next();
        Iterator cells = row.cellIterator();

        while (cells.hasNext()) {
            cell = (HSSFCell) cells.next();

            if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                System.out.print(cell.getStringCellValue() + " ");
            } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
                System.out.print(cell.getNumericCellValue() + " ");
            } else {
                //U Can Handel Boolean, Formula, Errors
            }
        }
        System.out.println();
    }

}