You for
should start from 0 and not 1 but you could try using iterator
Adjust following code to your needs
try {
// Open the Excel file
FileInputStream fis = new FileInputStream("D:\\Workspace\\test\\src\\test\\testdata.xls");
// Access the required test data sheet
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet sheet = wb.getSheet("testdata");
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) { // cycle throuh all rows
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
if (cellIterator.hasNext()) { //change to while if you need all columns, otherwise if you need the first column leave as it is...
Cell cell = cellIterator.next();
System.out.println("Running test case " + cell.getStringCellValue());
}
}
}
} catch (IOException e) {
System.out.println("Test data file not found");
}
finally
{
if (fis != null)
fis.close();
}
You can also check the type of a column using:
String tmp = "";
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
tmp = cell.getNumericCellValue() + "";
break;
case Cell.CELL_TYPE_STRING:
tmp = cell.getStringCellValue();
break;
// case Cell.<other types>: ... ; break;
}