码迷,mamicode.com
首页 > 其他好文 > 详细

openpyxl获取表格测试数据(类与对象)

时间:2020-04-03 23:48:50      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:range   font   图片   表格   style   actual   inf   expec   return   

from openpyxl import load_workbook

class Case:
def __init__(self):
self.case_id = None
self.title = None
self.method = None
self.url = None
self.data = None
self.expected = None
self.actually = None
self.result = None

技术图片

 

class ReadData:
def __init__(self, file_name):
self.file_name = file_name
self.wb = load_workbook(self.file_name)

def read_data(self, sheet_name):
self.sheet_name = sheet_name
sheet =self.wb[self.sheet_name]

case_data = []
for row in range(2, int(sheet.max_row)+1):
case = Case()
case.case_id = sheet.cell(row, 1).value
case.title = sheet.cell(row, 2).value
case.method = sheet.cell(row, 3).value
case.url = sheet.cell(row, 4).value
case.data = sheet.cell(row, 5).value
case.expected = sheet.cell(row, 6).value
case_data.append(case)
return case_data
if __name__==‘__main__‘:

 

openpyxl获取表格测试数据(类与对象)

标签:range   font   图片   表格   style   actual   inf   expec   return   

原文地址:https://www.cnblogs.com/sophia-985935365/p/12629524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!