David542
David542

Reputation: 110203

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?

Upvotes: 6

Views: 3678

Answers (2)

kindall
kindall

Reputation: 184201

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.

Upvotes: 12

David542
David542

Reputation: 110203

I did this a hack-ish way:

if str(sh.cell(1,col)).split(':')[0] == 'xldate':

Upvotes: 1

Related Questions