Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
5.9k views
by
How do I get the number of rows and columns count using POI in Selenium WebDriver?

2 Answers

0 like 0 dislike
by Contributing Tester (16 points)
Try This one...

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;

 public class ExcelRowAndColumnCount

{

   public static void main(String args[]) throws Exception

   {

       FileInputStream file = new FileInputStream("D://TestData.xlsx");

       XSSFWorkbook workbook = new XSSFWorkbook(file);

       XSSFSheet sheet = workbook.getSheet("SheetName");

       XSSFRow row = sheet.getRow(0);

       int colNum = row.getLastCellNum();

       System.out.println("Total Number of Columns : "+colNum);

       int rowNum = sheet.getLastRowNum()+1;

       System.out.println("Total Number of Rows  : "+rowNum);

   }

}
0 like 1 dislike
by
Better to use it with Dataprovider of TestNG
by Expert (572 points)
The TestNG's data provider wants us to write the code right?


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...