RE: Hii frnds….i need info about getting data from excel…how to get numeric data from excel???

Answered

I m unable to get numeric data example mobile number from excel n pass that value to some field…I used getnumericcellvalue() method to fetch the data…as send keys(char sequence) accepts char sequence I m unable to get neric data…m getting exception….pls do help me to sort this prblm…

Regards
Pradeep

Pradeep Train Asked on December 10, 2014 in Selenium WebDriver.
Add Comment
5 Answers

Hi Pradeep
Here I am writing a sample program to read both String and Numeric Data fromĀ  Excel file.

publicĀ  class ReadExcelData{
public static void main(String[] args){
Object[][] obj=new Object[6][2];
InputStream f=new FileInputStream(“Path of your Excel File”);
Workbook wb=WorkBookFactory.create(f);
Sheet s=wb.getSheetAt(0);
int rc=s.getLastRowNum();
for(int i=0;i<rc;i++)
{
Row r=s.getRow(i+1);
int cc=r.getLastCellNum();
for(int j=0;i<cc;j++)
{
Cell c=r.getCell(j);
if(c.getCellType()==c.CELL_TYPE_STRING)
{
obj[i][j]=c.getStringCellValue();
}
else if(c.getCellType()==c.CELL_TYPE_NUMERIC)
{
obj[i][j]=c.getNumericCellValue();
}

}
}
System.out.println(obj[i][j]);
}
}

Thanks & Regards
Samba.

Train Answered on December 11, 2014.

Hi samba
I want clarification regarding return type of the Readexceldata method coz as u mentioned in code value vl b different i’e numeric n string so how u decide return type fr dat method in excel library

on December 12, 2014.

Hi Pradeep, You can take the return type of readExcelData() as show below.

public static Object[][] readExcelData()
{
//paste above all the code here
return obj;
}

Thanks & Regards
Samba.

on December 13, 2014.

Thanks fr ur help samba…..but my requirement is I need to cal readexcelData() from another class and that method should give me the data, so that I can send that data to perticular field in my application….example
Class A
Readexceldata()
.
.
Some code.
.
.

Vl call that method in below class
Class B
A a1=new A()
String x=a1.readexceldata();

Send the above string to application using send keys

LoginPage lap=new LoginPage();
lap.send keys(x):

In such a situation how u differentiate between string data n numeric data…hope u got clear idea

on December 13, 2014.
Add Comment

Your Answer

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