import xlrd
def get_excel_data(excelDir,sheetName,caseName,*args):
resList=[]
workBook=xlrd.open_workbook(excelDir,formatting_info=True)
workSheet=workBook.sheet_by_name(sheetName)
colidx=[]
for i in args:
colidx.append(workSheet.row_values(0).index(i))
idx=0
for one in workSheet.col_values(0):
if caseName in one:
getcoldata=[]
for num in colidx:
tmp = workSheet.cell(idx,num).value
if is_json(tmp):
tmp = json.loads(tmp)
getcoldata.append(tmp)
resList.append(getcoldata)
idx += 1
return resList
def is_json(inStr):
try:
json.loads(inStr)
except:
return False
return True
if __name__ == '__main__':
res=get_excel_data('../data/testcase.xls','登录模块','Login','标题','URL','请求参数','响应预期结果')
for one in res:
print(one)