[Python] Identify fixed font color of cell values in excel using Python

Discussão em 'Python' iniciado por Stack, Janeiro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am reading a certain excel cell values which could have font color in red(#FF0000),green(#92D050) or cell could be emmpty.Based on thier color i need to assign fixed value to another variable.

    I tried to write below code but it doesnt works.Could you please guide me what am i missing.

    `Var1 = ""
    Var2 = ""
    if source_sheet['C11'].value == None:
    Var1 = "No Data"
    elif source_sheet['C11'].font.color.rgb == "#92D050":
    Var1 = "Red"
    elif source_sheet['C11'].font.color.rgb == "#FF0000":
    Var1 = "Green"
    print(Var1)`


    Cell C11 has numeric value with green(#92D050) font.However the print value is blank.

    Could you please advise what am i missing here.

    Regards Biru

    Continue reading...

Compartilhe esta Página