简体   繁体   中英

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"";
                     }
                 }

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

尝试在使用日期和时间的同时使用String Split,因为默认情况下,日期和时间都会同时使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM