-1

I am using data driven testing in selenium with java. I want to get the test data from ".xls" file. here there are multiple columns and rows are there. so I want data from a specific column name. but I don't know how many rows are available. bu I am able to get the number of rows in the ".xls" file by using .getPhysicalNumberOfRows() method.

Can anyone suggest

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Sasi Reddy
  • 11
  • 4

1 Answers1

0

You can select the specific row or column from excel using following code :

File   f = new File("/Users/Raj/Desktop/datafile.xls");  //Create File Object to locate file on system
        Workbook w = Workbook.getWorkbook(f); //Activate the Workbook
        Sheet s = w.getSheet(0);  //Activate Sheet (either by name or id). Id starts with 0
        int rows= s.getRows() ; //Get Row Count
        int columns = s.getColumns();

        //sheet's columns and rows are started with (column = 0, row = 0)
        int firstColumn = 0;
        int secondColumn = 1;
        int secondRow = 1;

        int firstColumnData = Integer.parseInt(s.getCell(firstColumn, secondRow).getContents());
        int secondColumnData = Integer.parseInt(s.getCell(secondColumn, secondRow).getContents());

        int desiredData = firstColumnData + secondColumnData;

        System.out.println("First Column: "+firstColumnData + " Second Column Data: "+secondColumnData + " Sum Data: "+desiredData);

Hope it will help you.

RNS
  • 625
  • 5
  • 16