Quality Testing

Quality is delighting customers

How to fetch date from excel sheet using Apache POI library in selenium web driver.

Hello Mr. Anand Singh,

How to get date column from excel sheet in selenium web driver using Apache POI library.

I tried date column in "Date" format also in excel sheet. but not able fetch the date input from excel sheet.

Please share me the script for the above query.

Thanks
Geetha R

Views: 52

Reply to This

Replies to This Discussion

Can any one help me for the above query

Thanks

Geetha R

Hi 


While providing quality assurance services as software testing solutions we are used to create an utility function to facilitate above requirement. 


Please use below utility method in your framework's utility section class and let us know if it is resolving your issue.


private LocalDate readCellValueAsDate(final Row row, final int position) { 
  if (position == -1) {
        return null;   
}   
final Cell cell = row.getCell(position - 1);   
if (cell != null) { 
      cell.setCellType(CellType.NUMERIC);   
} else { 
      return null;   
}   
if (DateUtil.isCellDateFormatted(cell)) {
        try {
            return cell.getDateCellValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();       
} catch (final NullPointerException e) { 
          logger.error(e.getMessage()); 
          return null;       
}    }
    return null;
}


Thanks

Anand

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service