Hi I am new to python and was trying some codes to make my job easier. So here is my code
counter = 0
while True:
row_values = worksheet.row_slice(counter+1,start_colx=0, end_colx=4)
row['Dealer'] = int(row_values[0].value)
row['Name'] = str(row_values[1].value)
row['City'] = str(row_values[2].value)
counter += 1
if not row['Dealer']:
break
I am trying to break the while loop when row['Dealer'] is null, that is when the end of excel file is reached. But it doesn't seem to work somehow. It keeps on giving IndexError: list index out of range. Some help would be appreciated. Thanks
Hi I edited my code to the following below:
counter = 0
while True:
row_values = worksheet.row_slice(counter+1,start_colx=0, end_colx=30)
row['gg'] = worksheet.cell_value(1+counter,1).strip()
if not row['gg']:
break
row['Dealer'] = int(row_values[0].value)
row['Name'] = str(row_values[1].value)
row['City'] = str(row_values[2].value)
counter += 1
But the error is still the same! Help would be highly appreciated.
You can get the end of Rows using
worksheet.nrows
, for instance: