I want to read the cell(1,1) value in the excel sheet, it is date in the format of 21-08-18
.
I'm using the python package xlrd
to read the value, it returns the float value ex. like 4567.0
book = xlrd.open_workbook(path)
compSheet = book.sheet_by_name("sheet_name")
cell_value = compSheet.cell_value(1, 1)
How to know the data type of the cell before reading the value whether it is date
or string
or float
or etc.
You can get a cell's type to see if it's a date and compare that to xlrd's cell object definition (or directly compare it to the number as seen in that table, as cell.ctype just returns a number).
book = xlrd.open_workbook(path)
compSheet = book.sheet_by_name("sheet_name")
cell = compSheet.cell(1,1)
if cell.ctype is xlrd.XL_CELL_DATE:
print "Cell 1,1 is a date!"