Locked lesson.
About this lesson
Let's discuss another method to iterate through rows in an Excel spreadsheet when you need a little more control.
Exercise files
Download this lesson’s related exercise files.
20 - Existing Excel - Iterate Thru Rows.docx57.3 KB 20 - Existing Excel - Iterate Thru Rows SOLUTION.docx
55.7 KB
Quick reference
Existing Excel - Iterate Thru Rows
This is another way to Iterate through rows that gives you a little more control.
When to use
Use this method to iterate through rows in an Excel spreadsheet when you need a little more control.
Instructions
for row in ws.iter_rows(min_row=1, max_row=8, min_col=1, max_col=2):
for cell in row:
print(cell.value)
You can use this without the .value method by setting a values_only flag:
for row in ws.iter_rows(min_row=1, max_row=8, min_col=1, max_col=2, values_only=True):
for cell in row:
print(cell)
Hints & tips
- for row in ws.iter_rows(min_row=1, max_row=8, min_col=1, max_col=2):
- for row in ws.iter_rows(min_row=1, max_row=8, min_col=1, max_col=2, values_only=True):
Lesson notes are only available for subscribers.