2024-04-27 21:08:15 发布
网友
我试图获取调用函数的单元格的列号和行号,或者Excel中函数代码中传递的单元格的列号和行号
如果我在excel中调用一个用户定义函数(UDF),比如,=some_udf(A2:D2),并且在后端,也就是说,在使用xlwings用python编写此函数的定义的地方,我想获取调用此函数的单元格行号和列号,或者可以使用作为参数传递的范围来获取。我不知道该怎么做
=some_udf(A2:D2)
请帮忙! 或者如果有可能使用其他一些工具,比如openpyxl等,请告诉我
使用xlwings调用用户定义函数时,可以在函数定义中包含特殊参数caller,该参数将作为调用函数的范围对象:
caller
@xw.func def some_udf(your_arg, caller): # caller will not be exposed in Excel, so use it like so: # =some_udf(your_arg) # Now you can access infos about the caller, e.g.: caller.address caller.row caller.column
另见:https://docs.xlwings.org/en/stable/udfs.html#the-caller-argument
使用xlwings调用用户定义函数时,可以在函数定义中包含特殊参数
caller
,该参数将作为调用函数的范围对象:另见:https://docs.xlwings.org/en/stable/udfs.html#the-caller-argument
相关问题 更多 >
编程相关推荐