RE: How to retrieve data from excel having 5 rows and 5 columns?

Answered

While iterating it only providing first row data.pls provide a asolution?

surekha Train Asked on September 26, 2014 in Selenium WebDriver.
Add Comment
1 Answers
Best answer

This  way you can read the rows and clms from excel file

package utility;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.*;

public class Read_exl {
public  String filelocation;
public  FileInputStream ipstr = null;
public  FileOutputStream opstr =null;
private XSSFWorkbook wb = null;
private XSSFSheet ws = null;

public Read_exl(String filelocation) {
this.filelocation=filelocation;
try {
ipstr = new FileInputStream(filelocation);
wb = new XSSFWorkbook(ipstr);
ws = wb.getSheetAt(0);
ipstr.close();
} catch (Exception e) {
e.printStackTrace();
}

}

//To retrieve No Of Rows from .xls file’s sheets.
public int retrieveNoOfRows(String wsName){
int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return 0;
else{
ws = wb.getSheetAt(sheetIndex);
int rowCount=ws.getLastRowNum()+1;
return rowCount;
}
}

//To retrieve No Of Columns from .cls file’s sheets.
public int retrieveNoOfCols(String wsName){
int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return 0;
else{
ws = wb.getSheetAt(sheetIndex);
int colCount=ws.getRow(0).getLastCellNum();
return colCount;
}
}

Doctor Answered on September 26, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.