iterate through all rows in specific column openpyxl

Daniel Dahms picture Daniel Dahms · Jul 27, 2016 · Viewed 68.2k times · Source

I cannot figure out how to iterate through all rows in a specified column with openpyxl.

I want to print all of the cell values for all rows in column "C"

Right now I have:

from openpyxl import workbook
path = 'C:/workbook.xlsx'
wb = load_workbook(filename = path)
ws=wb.get_sheet_by_name('Sheet3')

for row in ws.iter_rows():
    for cell in row:
        if column == 'C':
            print cell.value

Answer

Jonathan Koren picture Jonathan Koren · Aug 21, 2017

Why can't you just iterate over column 'C' (version 2.4.7):

for cell in ws['C']:
   print cell.value