from xlrd import open_workbook
import os
class readExcel():
def get_xls(self):
path = os.path.split(os.path.realpath(__file__))[0]#获取当前路径
xlsPath = os.path.join(path, "testFile", 'case.xls')#拼接excel路径
print (xlsPath)
cls = []
file = open_workbook(xlsPath) #打开用例Excel
sheet = file.sheet_by_name('login')
nrows = sheet.nrows
for i in range(nrows): # 根据行数做循环
if sheet.row_values(i)[0] != u'case_name': # 如果这个Excel的这个sheet的第i行的第一列不等于case_name那么我们把这行的数据添加到cls[]
cls.append(sheet.row_values(i))
print (cls)
return cls
readExcel().get_xls()
注意事项:指定安装 xlrd 1.2.0,不然会报错