Search code examples
pythonexcelxlrd

How to find if excel cell is a date


If I do:

print sh.cell(1,col)

I get:

text:u''
text:u''
text:u'eng'
text:u''
xldate:41450.0
number:11.0
number:30.0
text:u'Reality TV'

However, if I do: print type(sh.cell(1,col)), I get:

<class 'xlrd.sheet.Cell'>

for all.

How would I get "text" or "xldate" or "number" -- i.e., the cell type -- from xlrd?


Solution

  • You want the ctype attribute of the Cell object. E.g.:

    sh.cell(1,col).ctype
    

    This is an integer that indicates the cell type. You want to compare to xlrd.XL_CELL_DATE; see documentation here.