读取excel
class ExcelUtil(object): def __init__(self, excelPath, sheetName): self.data = xlrd.open_workbook(excelPath) self.table = self.data.sheet_by_name(sheetName) #get titles self.row = self.table.row_values(0) #get rows number self.rowNum = self.table.nrows print(self.rowNum) #get columns number self.colNum = self.table.ncols print(self.colNum) #the current column self.curRowNo = 1 def next(self): r = [] while self.hasNext(): s = {} col = self.table.row_values(self.curRowNo) i = self.colNum for x in range(i): s[self.row[x]] = col[x] r.append(s) self.curRowNo += 1 # print(r) return r def hasNext(self): if self.rowNum == 0 or self.rowNum <= self.curRowNo : return False else: return True
结果:[{'No.': 1.0, 'API Purpose': '注册', 'Request URL': '/user/register', 'Request Method': 'POST', 'Request Data Type': 'Form', 'Request Data': '{"email":"${randomEmail}","password":"password"}', 'Encryption': 'No', 'Check Point': '"success":true'},
{'No.': '', 'API Purpose': '请求', 'Request URL': 'http:///mockjsdata/1/lihuobao/getDoctorinfo.action', 'Request Method': 'POST', 'Request Data Type': 'Data', 'Request Data': '', 'Encryption': '', 'Check Point': ''},
{'No.': '', 'API Purpose': '请求', 'Request URL': 'http://1/mockjsdata/1/doctor/list', 'Request Method': 'POST', 'Request Data Type': 'Data', 'Request Data': '', 'Encryption': '', 'Check Point': ''}]
目前还在学习中,希望会对大家有所帮助,觉得不错,就点赞支持一下。
另外,转载时请附带链接。谢谢!