0

I came across conditional formatting https://xlsxwriter.readthedocs.io/working_with_conditional_formats.html But not sure how to implement it. I have my result saved in dataframe, i am trying to do this color formatting based on if column2> column1: color column2 else: do nothing and save the excel file. any suggestions.

2 Answers 2

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()

Sign up to request clarification or add additional context in comments.

Comments

0
   worksheet.conditional_format('B1:B9' ,
                         {'type':'formula',
                          'criteria': '=AND($A1<$B1,$B1>0)',
                          'format':   format1})

1 Comment

In type area enter formula then the python interpreter will process for user defined formula in CRITERIA section. format1 is the format that we want to do. This is format col B from row 1 to 9 if col.B>col.A and Additional criteria is B1>0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.