How do I get the number of rows and columns count using POI in Selenium WebDriver?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

2 Answers

answered by (16 points)
0 votes
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);


answered by
–1 vote
Better to use it with Dataprovider of TestNG
commented by (552 points)
The TestNG's data provider wants us to write the code right?