0

I have a large dataset that I do not have direct access to and am trying to convert the data headers into column headings using Python and then returning it back to Excel.

I have created the function to do this and it works but I have hit a snag. What I want the Excel VBA to do is loop down the range and if the cell's value matches the criteria call the Python function and return the resulting list items in the columns moving across from the original cell. For example:

A1 holds the string to format, the functions returns B1, C1, D1, and so on. I can only get this to work if I hard code B1, C1, D1, etc.

Is there a way to do this via the get_address() range method? I think I can then use the offset() method but am not sure.

4

2 回答 2

0

谢谢你的帮助。我现在已经开始工作了,我对 Python、xlwings 和 Excel 的未来可能性感到非常兴奋。

一旦我通过排序的范围进行循环,我的问题就很简单了(顺便说一下,它很容易作为每个元素的每一行而不是每个单元格导入)。我已经在函数之外声明了我的列表,因此每次满足真实条件时都不会重置。看着我的单元格一次又一次地填充相同的值,我感到非常沮丧。一旦你知道如何简单:)

于 2015-02-23T21:54:08.683 回答
0

是的,您可以使用 offset 方法,并执行以下操作:

for x in range(1, 11): #loop through a range
if Range('A' + str(x)).value == 5: #to match your own criterion
    Range('A' + str(x)).offset(0, 1).value = ['apple', 'banana', 'pear'] #the returns of your own function
于 2015-02-23T03:49:22.477 回答