iterate through all rows in specific column openpyxl

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

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

You can also do this.

for row in ws.iter_rows():
   print(row[2].value)

With this you are still iterating through the rows (but not the cells) and only pulling the values from column C in the row to print.


You can specify a range to iterate over with ws.iter_rows():

import openpyxl

wb = openpyxl.load_workbook('C:/workbook.xlsx')
ws = wb['Sheet3']
for row in ws.iter_rows('C{}:C{}'.format(ws.min_row,ws.max_row)):
    for cell in row:
        print cell.value

Edit: per your comment you want the cell values in a list:

import openpyxl

wb = openpyxl.load_workbook('c:/_twd/2016-06-23_xlrd_xlwt/input.xlsx')
ws = wb.get_sheet_by_name('Sheet1')
mylist = []
for row in ws.iter_rows('A{}:A{}'.format(ws.min_row,ws.max_row)):
    for cell in row:
        mylist.append(cell.value)
print mylist