[Python] Python in Excel - xl() function can't handle variables?

Discussão em 'Python' iniciado por Stack, Fevereiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    So I've been trying to write some python code in Microsoft Excel. The code produces a cell reference, which should then be fed into the xl() function, so that the value of that cell will be returned.

    But the obstacle that I keep running into is that xl() doesn't seem to be able to accept variables.

    Eg, putting this python code in excel:

    ref = "A1"
    var = xl(ref)
    var


    …should return the value in cell A1. But it doesn't. It just returns a KeyError.

    Typing A1 directly into the xl() function (xl("A1")) works fine, but as soon as you put the cell reference into a variable excel can't handle this.

    How can I fix this or are there any workarounds to this?

    Preferably workarounds that don't involve the use of office add-ins

    Continue reading...

Compartilhe esta Página