获取调用 xlwings UDF 的单元格的行和列?

Get the row and column of the cell, where xlwings UDF was called?

我正在使用 xlwings 库并且正在创建自定义 UDF 函数。

@xw.func
def hello(name):
    return f"Hello {name}!{os.getcwd()}"

如何获取调用函数的单元格所在的行和列?

澄清一下,我想访问函数内的行和列。

您可以使用 caller 参数,参见:https://docs.xlwings.org/en/stable/udfs.html#the-caller-argument

@xw.func
def hello(name, caller):
    # caller is an xlwings range object
    row, col = caller.row, caller.column
    return f"Hello {name}!{os.getcwd()}"