AAP
AAP

Reputation: 13

How to read Date from an Excel using Selenium WebDriver and return it?

I am trying to read date from Excel file but its giving the following Exception:

Cannot get a text value from a numeric cell.

And I want to return cellData whatever it may be(string, int, date).

Here's my code:

public static String getCellData(int RowNum, int ColNum, String SheetName ) throws Exception{
                try{
                    ExcelWSheet = ExcelWBook.getSheet(SheetName);
                    Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);                      
                    String CellData = Cell.getStringCellValue();                        
                    return CellData;
                 }catch (Exception e){
                     Log.error("Class Utils | Method getCellData | Exception desc : "+e.getMessage());
                     DriverScript.bResult = false;
                     return"";
                     }
                 }

Upvotes: 1

Views: 7801

Answers (2)

Kavita Kalia
Kavita Kalia

Reputation: 1

Try to use String Split while taking date and time as by default it takes both.

Upvotes: 0

Rajnish Kumar
Rajnish Kumar

Reputation: 2938

Apeksha Pawar please do one thing in your excel sheet where you are keeping date please change the format of that cell to string one of the way to do that is :

suppose your date is 04/01/2016  then add a Single "'" (comma) in front of the date value it will change its format to string and after that your above code will work.

there are multiple ways to do the same please follow your excel guidelines

Upvotes: 2

Related Questions