import xlrd
from xlrd import xldate_as_tuple
from datetime import datetime
# 处理excel依赖xlrd模块 pip install xlrd
# 读取excel文件
file_path = '测试.xls'
excel_data = xlrd.open_workbook(file_path)
# 获取第一个sheet页
sheet = excel_data.sheet_by_name("预约明细")
# 总行数
rows = sheet.nrows
# 获取列(经常读取到的excel可能存在空白行或者空白列,这里根据第一行的数据获取要导入的数据的列数)
rowlsts = [i for i in sheet.row_values(0) if i != '']
for r in range(1, sheet.nrows):
if sheet.cell(r, 1).ctype == 3:
dialog_date = datetime(*xldate_as_tuple(sheet.cell(r, 5).value,0))//读取datetime单元格
else:
dialog_date = sheet.cell(r, 5).value
dialog_datetime = xlrd.xldate.xldate_as_datetime(sheet.cell(r,3).value,0)//读取只有时分秒的单元格(23:25:03)
print(dialog_datetime)