openpyxl no attribution error
Solution 1
According to https://bitbucket.org/openpyxl/openpyxl/issues/278/get_highest_row-column-are-unreliable
In newest openpyxl
, which has removed get_highest_row
and get_highest_column
method. They have been replaced by max_row
and max_column
property
Solution 2
I tried it with openpyxl 2.3.5 and got the following
/usr/local/lib/python3.5/site-packages/openpyxl/worksheet/worksheet.py:350: UserWarning: Call to deprecated function or class get_highest_row (Use the max_row property). def get_highest_row(self):
So as you are using 2.4 they probably removed it from there as it was deprecated already in 2.3.5.
EDIT: In the documentation for 2.4 this method is not mentioned any longer
Jacky Zhang
Updated on June 15, 2022Comments
-
Jacky Zhang almost 2 years
Python 3.5 openpyxl 2.4
Hi everyone, I got a simple but confusing problem here. FYI the API doc relating to worksheet is
http://openpyxl.readthedocs.io/en/default/api/openpyxl.worksheet.worksheet.html
Here is some simple code for testing.
# -*- coding: utf-8 -*- from openpyxl import load_workbook wb2 = load_workbook('example.xlsx') print (wb2.get_sheet_names()) ws = wb2.get_sheet_by_name('Sheet1') print (type(ws)) print (ws.calculate_dimension()) list = [] for i in ws.rows: print ('\n') for cell in i: list.append(cell.value) print(str(cell.value).encode('utf-8')) print (type(ws)) ws.get_highest_row()
here's what turned out eventually
<class 'openpyxl.worksheet.worksheet.Worksheet'> Traceback (most recent call last): File "script.py", line 17, in <module> ws.get_highest_row() AttributeError: 'Worksheet' object has no attribute 'get_highest_row'
I run into the problem where it says that
get_highest_row
is not an attribute. This seems correct since this function is under classworksheet.worksheet
(from API doc), andws
isworksheet.worksheet.Worksheet
(I've no idea what that is) may inherits some functions so it can still calldimension()
, but can someone tell me how to fix this? I want to check through one specific row or column and do some sorting with varying length of cols and rows. Any help is appreciated!-
Jacky Zhang almost 8 yearsI realized that I can use the ws.max_row to get the row number, but still I want to understand what cause the previous error.
-
-
Jacky Zhang almost 8 yearsYou‘’re right probably, I think they need to update this on their API library website.
-
DAXaholic almost 8 yearsThey have - your link in the question just points to the documentation for 2.3.5 which still includes the method as I wrote. I added the link to the doc for 2.4 to my answer which does not inlcude the method any longer.
-
Charlie Clark almost 8 yearsThe idea is to deprecate nearly all the
get_*
methods replacing them with more Pythonic idioms. We're following a fairly rapid deprecation strategy to keep the documentation simple but public APIs will be around for at least one release after deprecation. All deprecations are in the change notes.