Tuesday, 29 October 2013

READING DATA FROM EXCEL SHEET USING SELENIUM WEBDRIVER

READING DATA FROM EXCEL SHEET USING SELENIUM WEBDRIVER

import java.io.File;

import acclerators.Baseinfo;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class Excel extends Baseinfo{
public static Object[][] getTableArray(String filepath,String sheetname,String testcase) throws Exception{
       String[][] tabArray=null;
       try
       {
           Workbook workbook = Workbook.getWorkbook(new File(filepath));
           Sheet sheet = workbook.getSheet(sheetname); 
           int startRow,startCol, endRow, endCol,ci,cj;
           
           
Cell tableStart=sheet.findCell(testcase);
           
           startRow=tableStart.getRow();
           startCol=tableStart.getColumn();

           Cell tableEnd= sheet.findCell(testcase,startCol+1,startRow+1, 100, 64000,false);               

           endRow=tableEnd.getRow();
           endCol=tableEnd.getColumn();
           System.out.println("startRow="+startRow+", endRow="+endRow+", " +
                   "startCol="+startCol+", endCol="+endCol);
           tabArray=new String[endRow-startRow][endCol-startCol-1];
           ci=0;

           for (int i=startRow+1;i<=endRow;i++,ci++)
           {
             cj=0;
           for (int j=startCol+1;j<endCol;j++,cj++)
           {
             tabArray[ci][cj]=sheet.getCell(j,i).getContents();
           }
           }
           return(tabArray);
       }
       catch (Exception e) 
       {
System.out.println(e+Thread.currentThread().getStackTrace()[1].getClassName());
return null;
}
       }

No comments:

Post a Comment