July 16, 2014 · python xlrd

Reading dates from Excel with Python and XLRD

We have an Excel file, one of its columns is composed of cells with dates, like this:

25/05/1944  

This is how to read such a cell with Python and xlrd:

birthday_xls = ws.cell_value(curr_row, 5)  
if birthday_xls:  
    birthday_int = xlrd.xldate_as_tuple(int(birthday_xls), 0)

birthday = dt.date(birthday_int[0], birthday_int[1], birthday_int[2])

student.birthday = birthday  

These are the imports:

import datetime as dt  
import xlrd  
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket
Comments powered by Disqus