excel中有日期格式的单元格 用python读的时候 写了以下循环 但报错 不知道错在了哪里 请各位大神赐教
def FormatDatetimeValue(file= '.../xx.xlsx',by_name=u'xx'): data = open_excel(file) table = data.sheet_by_name(by_name) nrows = table.nrows #行数 ncols = table.ncols #列数 date=[] for row in range(0,nrows): for col in range(0,ncols): cell = sheet.cell(row,col) if cell.ctype == 3: # 3 means 'xldate' , 1 means 'text month, day,year = xlrd.xldate_as_tuple(cell.value,0)[:3] py_date = datetime.date(month,day,year) date.append(py_date.strftime('%m-%d-%Y'))
|