第三方库openPyxl读取excel文件
import openpyxl from openpyxl.worksheet.worksheet import Worksheet def openpyxl_read(): #1、打开文件 workbook = openpyxl.load_workbook("cases.xlsx") #2、获取标签 sheet:Worksheet=workbook["Sheet1"] #3、获取所有的数据内容 values = list(sheet.values) #4、将列表嵌套元组转成嵌套字典 title = values[0] rows = values[1:] #列表推导式 # new_cases=[dict(zip(title,row))for row in rows] new_cases=[] for row in rows: new_case=dict(zip(title,row)) new_cases.append(new_case) return new_cases openpyxl_read()
cases.xlsx