一、excel 数据以列表嵌套字典形式展示
excel数据:
以列表嵌套字典形式展示:
from openpyxl import load_workbook
filename = r'E:\learn_python\pri_package\data\case_01.xlsx'
#打开excel
wb = load_workbook(filename)
#读取工作簿
sheet = wb['login']
#列表形式
data = list(sheet.values)
#列表嵌套字典形式
dict_data = [dict(zip(data[0],i)) for i in data[1:]]
print(dict_data)
输出
二、从excel读取数据并导入测试用例中(以登录函数为例)
excel封装:
from openpyxl import load_workbook
def read_excel_dict(filename,sheetname):
wb = load_workbook(filename)
sheet = wb[sheetname]
excel_data = list(sheet.values)
tit