0

I am trying to insert a value n into a specific H column from position H10:H20

So, I tried the below

start_index = int(10)
for n in range(20):
    print(type(n))  # this returns int
    range('H' + str(start_index)).value = n
    start_index = start_index + 1 

However, the above code results in the below error

      2 for n in range(20):
      3     print(type(n))
----> 4     range('H' + str(start_index)).value = n
      5     start_index = start_index + 1

TypeError: 'str' object cannot be interpreted as an integer

But my n is an integer.

The Great
  • 6,010
  • 5
  • 18
  • 62

1 Answers1

1

Try the following from xlwings import range as xlrange and rename the code at line 4 as xlrange.

Or use import xlwings and at line 4 use xlwings.range.

Try to avoid asterisk in your import statements in order to avoid polluting the namespace. For more info check this post

Echchama Nayak
  • 1,162
  • 2
  • 21
  • 38
  • This is the related post - https://stackoverflow.com/questions/71537265/get-cell-location-based-on-its-value-using-xlwings – The Great Mar 19 '22 at 10:15