我正在尝试在 Python 中编写一个简单的用户定义函数,我将值传递给 from Excel
via Xlwings
。我遇到了一些带有加载项的示例,您需要导入用户定义的函数,但这似乎过于复杂。
为什么我的示例不起作用?
VBA:
Function Hello(name As String) As String
RunPython ("import Test; Test.sayhi(name)")
End Function
蟒蛇(Test.py
):
from xlwings import Workbook, Range
def sayhi(name):
wb = Workbook.caller()
return 'Hello {}'.format(name)
错误:
NameError: name 'name' is not defined