package readerexcel;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import jxl.Row;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;
public class readexcel_7 {
public static void main( String [] args ) {
try {
InputStream input = new FileInputStream("D://prova.xls");
POIFSFileSystem fs = new POIFSFileSystem(input);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
Iterator<Row> rows = sheet.rowIterator();
while(rows.hasNext()) {
HSSFRow riga = sheet.getRow(0);
System.out.println("N. Riga = " + ((HSSFRow) rows).getRowNum());
Iterator cells = ((HSSFRow) rows).cellIterator();
while(cells.hasNext()) {
HSSFCell cell = riga.getCell(0);
System.out.println( "N. Cella = "
+ cell.getCellNum() );
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
System.out.println(cell.getNumericCellValue());
break;
}
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
System.out.println(cell.getStringCellValue());
break;
default:
System.out.println(
"unsuported cell type" );
break;
}
}
}
} catch ( IOException ex ) {
ex.printStackTrace();
}
}
}