比较两列和使用python在Excel中更大的颜色?

时间:2018-11-27 11:39:49

标签: python excel dataframe xlsxwriter

我遇到了条件格式https://xlsxwriter.readthedocs.io/working_with_conditional_formats.html 但是不确定如何实现它。 我将结果保存在数据框中,我正在尝试根据column2> column1进行这种颜色格式化: 颜色列2 否则:无所事事 并保存excel文件。 任何建议。

1 个答案:

答案 0 :(得分:2)

for row in table:
    ws.write_row(i, 0, row)

    i += 1
    print("for i:", i)
    cell_pointer1 = "C${}".format(i) 
    cell_pointer2 = "D${}".format(i) 
    cell_pointer3 = "E${}".format(i) 
    print("cell pointer2:", format(cell_pointer2))

    ws.conditional_format(format(cell_pointer2) ,
        {'type':     'cell',
         'criteria': '>=',
         'value' : format(cell_pointer1),
         'format':   format2,
        })


    ws.conditional_format(format(cell_pointer2) ,
        {'type':     'cell',
         'criteria': '<',
         'value' : format(cell_pointer1),
         'format':   format1
        })

    ws.conditional_format(format(cell_pointer3) ,
       {'type':     'cell',
        'criteria': '>=',
        'value' : format(cell_pointer1),
        'format':   format2,
       })


    ws.conditional_format(format(cell_pointer3) ,
       {'type':     'cell',
        'criteria': '<',
        'value' : format(cell_pointer1),
        'format':   format1
       })

ws.set_column(0,0,25)

wb.close()