private static HSSFSheet ExcelWSheet;
private static HSSFWorkbook ExcelWBook;
private static HSSFCell Cell;
private static HSSFRow Row;
private static String[][] getTableArray(String FilePath, String SheetName) throws Exception
{
FileInputStream ExcelFile = null;
String[][] tabArray = null;
try{
ExcelFile = new FileInputStream(FilePath);
// Access the required test data sheet
ExcelWBook = new HSSFWorkbook(ExcelFile);
ExcelWSheet = ExcelWBook.getSheet(SheetName);
int startCol = 1;
int ci=0;
int totalRows = ExcelWSheet.getPhysicalNumberOfRows();
int totalCols = ExcelWSheet.getRow(1).getLastCellNum();
System.out.println(totalRows);
System.out.println(totalCols);
tabArray=new String[totalRows][totalCols];
DataFormatter formatter = new DataFormatter();
for (int j=1;j<=totalRows;j++, ci++)
{
//totalCols = ExcelWSheet.getRow(j).getPhysicalNumberOfCells();
//tabArray=new String[totalRows][totalCols];
int cj=0;
for (int l = 1; l < totalCols;l++, cj++) {
//tabArray[ci][cj] = getCellData(j, l);
Cell = ExcelWSheet.getRow(j).getCell(l);
String CellData = formatter.formatCellValue(Cell);
System.out.println(CellData);
tabArray[ci][cj] = CellData;
System.out.println(j);
System.out.println(l);
System.out.println(tabArray[ci][cj]);
System.out.println("tabArray["+ci+"]["+cj+"]: "+tabArray[ci][cj]);
}
}
System.out.println(tabArray);
}
catch (FileNotFoundException e)
{
System.out.println("Could not read the Excel sheet");
e.printStackTrace();
}
catch (IOException e)
{
System.out.println("Could not read the Excel sheet");
e.printStackTrace();
}finally {
ExcelFile.close();
}
return tabArray;
}
///// Cell = ExcelWSheet.getRow(j).getCell(l); here where its throwing null pointer exception.
coloumns heading are TestCases,Enquiry ID, Sl No., Material
need to read from the 2nd column Enquiry ID only and pass one by one in data driven framework.
want to read enquiry ids from excel and pass it to my @test method