您的位置:首页 > 编程语言 > Python开发

python学习(五)--- 处理Excel

2018-02-24 11:48 423 查看
#打开excel文件返回目标sheet
def OpenExcelFile():
wb = load_workbook(excel_file_path_)
#print(wb.sheetnames)
sheet = wb.get_sheet_by_name('Sheet1')
#print(sheet['C'][0].value)
print('max col is %d' % sheet.max_column)
print('max row is %d' % sheet.max_row)
return sheet

#将excel文件中所有视频时间信息转化为dict,用于后续查询
def GetVideosTimeInfo():
sheet = OpenExcelFile()
video_dict = defaultdict(list)
for i in range(1,sheet.max_row):
index = sheet[str(i+1)][0].value
for j in range(1,sheet.max_column):
seconds = TimeFormatToSeconds(str(sheet[str(i+1)][j].value))
video_dict[index].append(seconds)
#print(video_dict)
return video_dict


参考

用python读写excel的强大工具:openpyxl
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: