def set_columns_pass_style(self, sheet_name: str, result: str) -> None:
"""set columns style and write the fail/pass results into excel"""
workbook = openpyxl.load_workbook(sheet_name)
sheet = workbook.active
sheet.row_dimensions[1].height = 26
for cell in sheet[1]: # Adjust title style
sheet.column_dimensions[get_column_letter(cell.column)].width = len(cell.value) + 1
cell.fill = PatternFill(start_color="8DB4E2", end_color="8DB4E2", fill_type="solid")
cell.font = Font(name="Times New Roman", size=12, bold=True)
cell.alignment = Alignment(horizontal='center', vertical='center')
sheet["L3"] = result # set pass/fail font
sheet.merge_cells("L3:M7")
if result == "pass":
sheet['L3'].fill = PatternFill(start_color="007E1C", end_color="007E"
"1C", fill_type="solid")
else:
sheet['L3'].fill = PatternFill(start_color="FF0000", end_color="FF0000", fill_type="solid")
sheet["L3"].font = Font(name="Times New Roman", size=30, bold=True)
sheet["L3"].alignment = Alignment(horizontal='center', vertical='center')
workbook.save(sheet_name)
设置第一行数据的行高
workbook = openpyxl.load_workbook(sheet_name)
sheet = workbook.active
sheet.row_dimensions[1].height = 26
sheet.column_dimensions[get_column_letter(cell.column)].width = len(cell.value) + 1
cell.fill = PatternFill(start_color="8DB4E2", end_color="8DB4E2", fill_type="solid")
cell.font = Font(name="Times New Roman", size=12, bold=True)
cell.alignment = Alignment(horizontal='center', vertical='center')
sheet.merge_cells("L3:M7")
fill_green = PatternFill(start_color="008000", end_color="008000", fill_type="solid")
fill_green_cells = ["R3", "S3", "R6", "S6"]
for cell in fill_green_cells:
ws[cell].fill = fill_green
def set_judgement(self, sheet_name: str) -> None:
"""set header style and set judgement"""
workbook = openpyxl.load_workbook(sheet_name)
ws = workbook.active
# Adjust title style
ws.row_dimensions[1].height = 26
for cell in ws[1]:
ws.column_dimensions[get_column_letter(cell.column)].width = len(cell.value) + 1
cell.fill = PatternFill(start_color="8DB4E2", end_color="8DB4E2", fill_type="solid")
cell.font = Font(name="Times New Roman", size=12, bold=True)
cell.alignment = Alignment(horizontal='center', vertical='center')
# set judgement
##省略判定内容
fill_green = PatternFill(start_color="008000", end_color="008000", fill_type="solid")
fill_yellow = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid")
fill_red = PatternFill(start_color="FF0000", end_color="FF0000", fill_type="solid")
font_blue = Font(name="Times New Roman", size=10, color="5569FA", bold=True)
fill_green_cells = ["R3", "S3", "R6", "S6"]
fill_red_cells = ["R4", "S4", "R8", "S8", "R10", "S10"]
fill_yellow_cells = ["R7", "S7"]
font_blue_cells = ["L3", "T3", "T4", "L6", "T6", "T7", "T8", "L10"]
for cell in font_blue_cells:
ws[cell].font = font_blue
for cell in fill_green_cells:
ws[cell].fill = fill_green
for cell in fill_red_cells:
ws[cell].fill = fill_red
for cell in fill_yellow_cells:
ws[cell].fill = fill_yellow
workbook.save(sheet_name)