PatternFill 整行 openpyxl

PatternFill entire row openpyxl

我有一个作为 df 引入的 excel 文件。我想根据名称突出显示整行。到目前为止,我只能突出显示一列,但我希望突出显示应用于所有列。这是我目前所拥有的,它贯穿每个名称并为其应用高亮颜色,在不再找到该名称后,它移动到下一个名称并应用第二种高亮颜色,等等。

alist= df['NAME'].unique()
colorlist = ['efde6b','f4848d','bdbcff','75b56a','fcd7bd','f4b7c7','f79b74','a7d4f2']
count = 0
for a in alist:
    color = colorlist[count]
    color = str(color)
    for row in ws.iter_rows(1):
        for cell in row:
            if cell.value == a:
                cell.fill = PatternFill(start_color=color,
                                            end_color=color,
                                            fill_type='solid')
     count = count + 1
alist = test['NAME'].unique()
colorlist = ['efde6b','f4848d','bdbcff','75b56a','fcd7bd','f4b7c7','f79b74','a7d4f2']
count = 0
for a in alist:
    color = colorlist[count]
    color = str(color)
    for row in ws.iter_rows(1):
        for c in row:
            if c.value == a:
                row = c.row
                col = 1
                # print(row, col)
                while col < 9:
                    ws.cell(row=row, column=col).fill = PatternFill(start_color=color,
                                                    end_color=color,
                                                    fill_type='solid')
                    col = col + 1