자동화 테스트 excel 봉인 클래스

-- coding: utf-8 --


“”"


@Time: 2019/7/22 9:15 @Auth: 소소@File: excel_frame.py @IDE : PyCharm @Motto: your story may not have such a happy beginning , but that doesn’t make who you are . It is the rest of your story, who you choose to be


“”"import openpyxl
class HandleExcel:''작업 excel 클래스''def init(self,filename,sheetname=None):self.filename = filename self.sheetname = sheetname
def get_excel(self):
    """
     excel 
    :return:
    """
    wb = openpyxl.load_workbook(self.filename)
    if self.sheetname is None:
        ws = wb.active
    else:
        ws = wb[self.sheetname]
    head_tuple = tuple(ws.iter_rows(max_row=1, values_only=True))[0]
    one_list = []
    for other_tuple in tuple(ws.iter_rows(min_row=2, values_only=True)):
        one_list.append(dict(zip(head_tuple, other_tuple)))
    return one_list

def write_excel(self, row, actual_col, actual, result_col, result):
    """
     excel 
    :param row: 
    :param actual_col: 
    :param actual: 
    :param reslut_col: 
    :param result: 
    :return:
    """
    wb = openpyxl.load_workbook(self.filename)
    if self.sheetname is None:
        ws = wb.active
    else:
        ws = wb[self.sheetname]
    if isinstance(row, int) and (2 <= row <= ws.max_row):
        ws.cell(row=row, column=actual_col, value=actual)
        ws.cell(row=row, column=result_col, value=result)
        wb.save(self.filename)
        wb.close()
    else:
        print(" ")

if name == ‘main’: do_excel = HandleExcel(‘cases.xlsx’) do_excel.get_excel() do_excel.write_excel(2, 10, 10)

좋은 웹페이지 즐겨찾기