from xlrd import open_workbook
import os
path = os.path.split(os.path.realpath(__file__))[0]
class readExcel():
def get_xls(self, xls_name, sheet_name): # xls_name填写用例的Excel名称 sheet_name该Excel的sheet名称
cls = []
# 获取用例文件路径
xlsPath = os.path.join(path, "testfile", xls_name)
file = open_workbook(xlsPath) # 打开用例Excel
sheet = file.sheet_by_name(sheet_name) # 获得打开Excel的sheet
# 获取这个sheet内容行数
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
Python读取excel中的测试用例(一)
于 2022-02-14 09:19:48 首次发布