How to change the color based on text in excel using Python?

后端 未结 2 1418
感动是毒
感动是毒 2021-01-22 18:22

In Excel cell text will vary from Pass to Fail.I have to give background color green for Pass(pass/Passed/passed) and red for Fail(fail/Failed/failed) respectively. How to chang

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-22 18:40

    You can create styles using easyxf and then pass them as arguments to your write method.

    For example:

    style_pass = xlwt.easyxf('pattern: pattern solid, fore_colour green;')
    style_fail = xlwt.easyxf('pattern: pattern solid, fore_colour red;')
    worksheet.write_merge(6, 6, 3, 3,'Pass', style=style_pass)
    worksheet.write_merge(7, 7, 3, 3,'Fail', style=style_fail)
    

提交回复
热议问题