openpyxl iterate through cells of column => TypeError: 'generator' object is not subscriptable
<p>i I want to loop over all values op a column, to safe them as the key in a dict. As far as i know, everything is ok, but python disagrees.</p>

<p>So my question is: "what am i doing wrong?"</p>

<pre><code>&gt;&gt;&gt; wb = xl.load_workbook('/home/x/repos/network/input/y.xlsx')
&gt;&gt;&gt; sheet = wb.active
&gt;&gt;&gt; for cell  in sheet.columns[0]:
...     print(cell.value)
... 
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: 'generator' object is not subscriptable
</code></pre>

<p>I must be missing something, but after a few hours of trying, I must throw in the towle and call in the cavalecry ;)</p>

<p>thanks in advance for all the help!</p>

<p>===================================================================</p>

<p>@Charlie Clark: thanks for taking the time to answer. The thing is, I need the first column as keys in a dict, afterwards, I need to do</p>

<pre><code>for cell  in sheet.columns[1:]:
</code></pre>

<p>so, while it would resolve my issue, it would come back to me a few lines later, in my code. I will use your suggestion in my code to extract the keys.</p>

<p>The question I mostly have is: </p>

<p>why doesn't it work, I am sure I used this code snippet before and this is also how, when googling, people are suggesting to do it.</p>

<p>==========================================================================</p>

<pre><code>&gt;&gt;&gt; for column in ws.iter_cols(min_col = 2):
...     for cell in column:
...             print(cell.value)
</code></pre>

<p>goes over all columns of the sheet, except the first. Now, I still need to exclude the first 3 rows </p>

<p>apparently, the openpyxl module got upgraded to 2.4, without my knowledge.</p>

<pre><code>&gt;&gt;&gt; for col in ws.iter_cols(min_col = 2, min_row=4):
...     for cell in col:
...         print(cell.value)
</code></pre>

<p>should do the trick.
I posted this in case other people are looking for the same answer.</p>

<pre><code>iter_cols(min_col=None, max_col=None, min_row=None, max_row=None)[source]

Returns all cells in the worksheet from the first row as columns.

If no boundaries are passed in the cells will start at A1.

If no cells are in the worksheet an empty tuple will be returned.
Parameters: 

    min_col (int) â smallest column index (1-based index)
    min_row (int) â smallest row index (1-based index)
    max_col (int) â largest column index (1-based index)
    max_row (int) â smallest row index (1-based index)

Return type:    

generator
</code></pre>

python excel loops openpyxl