接下来封装一个用来读取excel文件的类 excel_util.py
import xlrd import os class ExcelUtil(object): def __init__(self,excelPath=None,index=None): if excelPath == None: self.excelPath = os.path.join(os.getcwd()+'/config/casedata.xls') else: self.excelPath = excelPath if index == None: self.index = 0 else: self.index = index self.data = xlrd.open_workbook(self.excelPath) self.table = self.data.sheets()[self.index] def get_lines(self): rows = self.table.nrows if rows >= 1: return rows else: return None def get_data(self): result = [] rows = self.get_lines() if rows != None: for i in range(rows): data = self.table.row_values(i) result.append(data) return result else: return None
这个是excel截图