接下来封装一个用来读取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截图
标签:web,None,rows,index,python,unittest,excelPath,data,self
来源: https://www.cnblogs.com/huaniaoyuchong/p/13919764.html