[Python] condition formatting rule formula want to pass text value using variable in python...

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024.

  1. Stack

    Stack Membro Participativo

    I have code as below, instead of passing column G directly, want to pass it through variable


    worksheet = srcfile[sheetName]
    rule = ruleno
    rule = formatting.Rule(type='expression')
    color_fill = styles.PatternFill(start_color=colorcode,
    end_color=colorcode, fill_type='solid')
    rule.formula = [f'ISNUMBER(SEARCH("G", {cellref}))']
    print(rule.formula)

    ```

    Instead of manually searching for text "G" want to assign it text variable and then pass it in the formula




    textval = "G"



    worksheet = srcfile[sheetName]
    rule = ruleno
    rule = formatting.Rule(type='expression')
    color_fill = styles.PatternFill(start_color=colorcode,
    end_color=colorcode, fill_type='solid')
    rule.formula = [f'ISNUMBER(SEARCH(textval, {cellref}))']
    print(rule.formula)

    Continue reading...

Compartilhe esta Página