[英]passing array as parameter of RunPython script in VBA (xlwings)
In my VBA sub, I'm calling a python script using the command RunPython from xlwings. 在我的VBA子程序中,我使用xlwings中的RunPython命令调用python脚本。 I would like to call a function that takes an array as parameter.
我想调用一个以数组作为参数的函数。 How can I convert the VBA data type into a list readable by Python?
如何将VBA数据类型转换为Python可读的列表?
Code: 码:
RunPython("import script; script.query(dates=argsArray, queryString='"& myString &"')
I can successfully pass a string using &, although i don't know how to pass the array argsArray as parameter. 我可以使用&成功传递一个字符串,虽然我不知道如何将数组argsArray作为参数传递。
Have a look at converters. 看看转换器。
http://docs.xlwings.org/en/stable/converters.html?highlight=array http://docs.xlwings.org/en/stable/converters.html?highlight=array
What you can do is pass the Range address as a string and then get the values as as an array. 您可以做的是将Range地址作为字符串传递,然后将值作为数组获取。 From the documentation:
从文档:
arr = xw.Range('A1:A3').options(np.array, ndim=2).value
where you would replace 'A1:A3' with argsArrayAddressString: 在哪里用argsArrayAddressString替换'A1:A3':
RunPython("import script; script.query(dates=argsArrayAddressString, queryString='"& myString &"')
then in your code: 然后在你的代码中:
arr = xw.Range(argsArrayAddressString).options(np.array, ndim=2).value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.