Slide 37
Slide 37 text
Conditional Formatting
import xlsxwriter
wb = xlsxwriter.Workbook('conditional_format.xlsx')
ws = wb.add_worksheet()
high = wb.add_format({'bg_color': '#FFC7CE', 'font_color': '#9C0006'})
low = wb.add_format({'bg_color': '#C6EFCE', 'font_color': '#006100'})
data = [
[88, 25, 33, 23, 67, 13],
[24, 100, 20, 88, 29, 33],
[6, 57, 88, 28, 10, 26],
[73, 78, 1, 96, 26, 45],
[36, 54, 22, 66, 81, 90],
]
for row, row_data in enumerate(data):
ws.write_row(row, 0, row_data)
ws.conditional_format('A1:F5', {'type': 'cell',
'criteria': '>=',
'value': 50,
'format': high})
ws.conditional_format('A1:F5', {'type': 'cell',
'criteria': '<',
'value': 50,
'format': low})
wb.close()