xldate_as_tuple无效

时间:2013-07-16 20:39:07

标签: python excel date xlrd

我正在阅读python中excel表的日期和时间。日期存储为浮点数,例如日期:excel中的3/11/2003 4:03:00作为37756.2180556读入python。在python我试图使用xlrd.xldate_as_tuple将此十进制数转换回常规日期,但我得到一个错误。

def Rule_2(sheet):
x = 2
y = 0
total_rows = sheet.nrows
total_columns = sheet.ncols
while y != total_columns:
    column_name = sheet.cell(0,y).value
    if column_name == "birthday":
        while x != total_rows:
            c_val = sheet.cell(x,y).value
            date = xlrd.xldate_as_tuple(c_val, book.datemode)
            print "row:", x + 1, date
            x += 1
    y += 1

此代码产生此错误:

Traceback (most recent call last):
  File "Data Cleaner.py", line 104, in <module>
    Rule_2(sheet)
  File "Data Cleaner.py", line 31, in Rule_2
    date = xlrd.xldate_as_tuple(c_val, book.datemode)
  File "/Library/Python/2.7/site-packages/xlrd/xldate.py", line 61, in xldate_as_tuple
    xldays = int(xldate)
ValueError: invalid literal for int() with base 10: ''

关于如何解决这个问题的任何想法,或者我做错了什么?

感谢您的帮助!

0 个答案:

没有答案