I would like to output conditional formatted Excel worksheets where for each column the condition is dependent on the value in the first row. Using the shown data frame cells A2, A4, B3, B4, C4, C5, D4, and E4 will be highlighted red.
import xlsxwriter
data = [
[1, 1, 5, 'A', 1],
[1, 4, 4, 'B', 0],
[2, 1, 5, 2, 2],
[1, 1, 5, 'A', 1],
]
wb = xlsxwriter.Workbook('testout.xlsx')
ws = wb.add_worksheet()
formatyellow = wb.add_format({'bg_color':'#F7FE2E'})
formatred = wb.add_format({'bg_color':'#FF0000'})
i=0
for row, row_data in enumerate(data):
print (row)
print (row_data)
ws.write_row(row, 0, row_data)
i += 1
ws.conditional_format(0,1,4,5, {'type':'text',
'criteria':'containing',
'value':'B',
'format':formatyellow})
ws.conditional_format(0,1,4,5, {'type':'cell',
'criteria':'==',
'value':'A$1',
'format':formatred})
This is what I'm trying to get:

Is there a way of getting this done using xlsxwriter?


wb.close()to the end. Second, I generate a different output from your code then what you have shown. Can you update your post to include more information about your system? (i.e. python version, xlsxwriter version, and os)