In order to complete a form on a website, I am using openpxyl to extract values from a certain row and column in an excel document. I complete the form, save it, and then fill out the following form using the values from the following row of the excel sheet.
Excel looks like this:
First Name Last Name DOB
George Hill 9/9/99
Sam Genius 8/8/88
Bill Smith 7/7/77
I want to run the below function three times and each time it runs prints out the next row:
def AddFirstName():
for i in range(3):
for row in ws.iter_rows(min_row=1, min_col=1, max_row=3,max_col=1):
for cell in row:
print(cell.value)
break
break # Tried to use breaks to break the loop so it only prints once for each loop
AddFirstName()
AddFirstName()
AddFirstName()
OR just run it outside the function like this:
for i in range(3):
for row in ws.iter_rows(min_row=1, min_col=1, max_row=3,max_col=1):
for cell in row:
print(cell.value)
break
break # Tried to use breaks to break the loop so it only prints once for each loop
This prints:
George
George
George
How do I fix this so that it prints:
George
Sam
Bill