Locked lesson.
About this lesson
Use this method when you want to grab an entire row - or a range of rows - from an Excel spreadsheet.
Exercise files
Download this lesson’s related exercise files.
19 - Existing Excel - Row Range.docx57.1 KB 19 - Existing Excel - Row Range SOLUTION.docx
55.6 KB
Quick reference
Existing Excel - Row Range
We can easily grab an entire row and a range of rows from an Excel spreadsheet.
When to use
Use this method when you want to grab an entire row, or a range of rows from an Excel spreadsheet.
Instructions
Notice there are no quotation marks around 1.
#Grab row 1:
row = ws[1]
# Now loop through to grab the values:
for cell in row:
print(cell.value)
# Grab a range of rows 1 thru 2
row_range = [1:2]
# Loop through them:
for row in row_range:
for x in row:
print(x.value)
Hints & tips
- One Row: row = ws[1]
- Row Range: row_range = [1:2]
Lesson notes are only available for subscribers.