I have an excel file that I have brought in as a df. I would like to highlight entire rows based off of names. So far, I am able to highlight only one column, but I would like the highlight applied to all columns. This is what I have so far, it runs through each name and applies a highlight color to it, after the name is no longer found, it moves on to the next name and applies the second highlight color, etc.
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
CodePudding user response:
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
