`iter_cols` gives a worksheet object has no attribute error?

After failing a bunch of times to get iter_cols to work with my code.

I tried using the example direct from documentation.

from openpyxl import load_workbook
from openpyxl import Workbook
wb = load_workbook("Trying web.xlsx")
ws = wb.active
ws.iter_cols()

for col in ws.iter_cols(min_row=1, max_col=3, max_row=2):
    for cell in col:
        print(cell)

>

Traceback (most recent call last): File “”, line 1, in ws.iter_cols() AttributeError: ‘Worksheet’ object has no attribute ‘iter_cols’

Answer

You should check the version of openpyxl you are using.

import openpyxl
print(openpyxl.__version__)

If that is an old version, you can get the newest version by upgrading