Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

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

Open 2 Answers 93 Views
0 2
How do I get the number of rows and columns count using POI in Selenium WebDriver?

2 Answers

0
0
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 (16 points)
-1
-1
Better to use it with Dataprovider of TestNG
answered by
1Comments
commented by (552 points)
The TestNG's data provider wants us to write the code right?

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.
...