Well, no matter, I found a solution, and here it is!
try: cell = worksheet.cell(row - 1, i) if cell.ctype == xlrd.XL_CELL_DATE: date = datetime.datetime(1899, 12, 30) get_ = datetime.timedelta(int(worksheet.cell_value(row - 1, i))) get_col2 = str(date + get_)[:10] d = datetime.datetime.strptime(get_col2, '%Y-%m-%d') get_col = d.strftime('%d-%m-%Y') else: get_col = unicode(int(worksheet.cell_value(row - 1, i))) except: get_col = unicode(worksheet.cell_value(row - 1, i))
A little explanation: it turns out that with xlrd you can check the type of cell and check whether it has a date or not. In addition, Excel seems like a weird way to save time. It saves them as floats (the left part for several days, the correct part for several hours), and then it takes a certain date (1899, 12, 30, it seems to work fine) and adds days and hours from the float to create a date. So, to create the date that I wanted, I just added them and saved only the first 10 letters ([: 10]) to get rid of the clock (00.00.00 or something ...). I also changed the order of days_months-years, because in Greece we use a different order. Finally, this code also checks to see if it can convert a number to an integer (I don't want any floats to appear in my program ...), and if all else fails, it just uses the cell as it is (in cases rows in cells ...). I hope you find this useful, I think there are other threads that say this is impossible or something like that.
Antoni4040
source share