Locked lesson.
About this lesson
We can grab an entire column of data from an Excel spreadsheet.
Exercise files
Download this lesson’s related exercise files.
18 - Existing Excel - Column and Column Range.docx57.2 KB 18 - Existing Excel - Column and Column Range SOLUTION.docx
57.7 KB
Quick reference
Existing Excel - Column and Column Range
We can grab an entire column of data from an Excel spreadsheet.
When to use
Use this method whenever you want to grab an entire column of data from an Excel spreadsheet.
Instructions
To grab an entire column, just call it.
col_b = ws['B']
That will return a tuple with the cell objects. To access them, you'll need to loop thru that tuple:
for cell in col_b:
print(cell.value)
You can also grab a range of columns:
col_range = ws['A':'B']
You'll also need to loop through those results to access the data individually.
for cell in col_range:
for x in cell:
print(x.value)
Hints & tips
- One Column: col_b = ws['B']
- Column Range: col_range = ws['A':'B']
Lesson notes are only available for subscribers.