Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find if excel cell is a date

Tags:

python

excel

xlrd

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?

like image 714
David542 Avatar asked Jun 28 '13 20:06

David542


People also ask

How do you check whether a cell is a date in Excel?

Best Answers you can use - ISTEXT([Your Column Name]) to check if it's a text entry and ISDATE([Your Column Name]) if it's a date. Instead of adding the ISTEXT for each of the columns, you can replace each of the ISDATE criteria to just say if the cell is not blank.

How do you count if there is a date in a cell?

In a blank cell enter the formula =COUNTA(A1:E15), and press the Enter key. In the formula, the range A1:E15 is the specific range you will count numbers of cells with data, and you can change it as you need.


1 Answers

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.

like image 129
kindall Avatar answered Oct 05 '22 08:10

kindall