2.6 隔行变色

from openpyxl import load_workbook
from openpyxl.styles import PatternFill

wb = load_workbook(filename=r'./办公自动化/files/orders.xlsx')

sh = wb.active

sh1 = wb.copy_worksheet(sh)
sh1.title = "隔行变色"

for i in range(1, sh1.max_row + 1):
    if i % 2 == 0:
        for cell in range(1, sh1.max_column + 1):
            sh1.cell(i, cell).fill = PatternFill('solid', fgColor="a1a3a6")

wb.save(filename=r'./办公自动化/files/orders.xlsx')