*I've tried to implement a solution that finds the row's coordinate for x1 that will be the start of the loop and row's coordinates for x4 what will be the end of the loop, but without succes. Maybe you can give me some ideas. *
wb_load = load_workbook("HighSchool.xlsx")
sheet_wb = wb_load["Sheet1"]
for row in sheet_wb.iter_rows():
for cell in row:
if cell.value == "x1":
x1_coordinate = cell.coordinate # C3
elif cell.value == None:
continue
elif cell.value == "x4":
x4_coordinate = cell.coordinate # C6
# I want to iter through C3 c6 using coordinates
CodePudding user response:
So as you already have the coordinates & what I understood is you wish to iterate through x1_coordinate to x4_coordinate in a loop... So, follow the below code... Not sure if this the best way though;
x1_coordinate = 'C3'
x4_coordinate = 'C6'
c1,r1 = list(x1_coordinate)
c2,r2 = list(x4_coordinate)
c1 = ord(c1.lower()) - 96 # To convert column into number
c2 = ord(c2.lower()) - 96 # To convert column into number
r1 = int(r1)
r2 = int(r2)
for c in range(c1,c2 1):
for r in range(r1,r2 1):
print(ws.cell(row=r, column=c).value)
# Output;
x1
y2
z3
x4