Search code examples
pythonopenpyxlnonetype

Python script having errorr 'NoneType' object has no attribute 'max_row'


need some help on the error that I am getting for my python script. I need to fetch the last row number in my excel work sheet.

Im using openpyxl==2.5.12.

Below is the code and error that I am getting.

code :

workbook = load_workbook(directory)
ws = workbook.active
max_row = ws.max_row

error : 'NoneType' object has no attribute 'max_row'.

I saw some past answers to the similar questions. I tried having Max_row(), it doesn't work. nrows also doesn't work.

Thanks in advance!


Solution

  • Your issue is nothing to do with max_row, the error is saying that there is no max_row available on an object which is NoneType, which indicates that the line workbook = load_workbook(directory) is not working correctly.

    I would suggest looking at whatever directory is, because it seems to be empty.