Saturday, March 21, 2015

How to play with excel sheet using APACHE POI and read excelsheet in Selenium WebDriver fraemwork ?

We can read excel using APACHE POI. its Java API to work with excel sheet.


HSS stands for Horrible spread sheet.

public FileInputStream instr;
public HSSFWorkbook wb = null;
public HSSFSheet ws = null;


            File file = new File(System.getProperty("user.dir"));
            DataFormatter dt = new DataFormatter();

            instr = new FileInputStream(file.getAbsolutePath() + "/Common/Config.xls");
            wb = new HSSFWorkbook(instr);
            ws = wb.getSheet("config");
        
           int row_count = ws.getLastRowNum() +1;           //to get count of total rows...
           int cell_count = ws.getLastCellNum() +1;  

           HSSFRow row = ws.getRow(0);                    //To get 1st row
           String column1text = dt.formatCellValue(row.getCell(0); //read text from first row and column




   

No comments:

Post a Comment