Python錯誤:AttributeError: 'Worksheet' object has no attribute 'get_highest_row' 解決辦法
https://blog.csdn.net/gaifuxi9518/article/details/80570746
今天開始學習《python程式設計快速上手》中的第12章:處理Excel電子表格。但是遇到了點小問題。
當我按照書中的方法獲取最大行和最大列的時候,出現了下面的錯誤提醒:
import openpyxl
wb = openpyxl.load_workbook('example.xlsx')
sheet = wb.get_sheet_by_name('Sheet1')
print(sheet.get_highest_row())
D:\>python test.py
test.py:5: DeprecationWarning: Call to deprecated function get_sheet_by_name (Use wb[sheetname]).
sheet = wb.get_sheet_by_name('Sheet1')
Traceback (most recent call last):
File "test.py", line 12, in <module>
print(sheet.get_highest_row())
AttributeError: 'Worksheet' object has no attribute 'get_highest_row'
print(sheet.get_highest_row())
AttributeError: 'Worksheet' object has no attribute 'get_highest_row'
書中提到的獲取最大行的方法是:get_highest_row(),獲取最大列的方法是:get_highest_row()。
多次比對書中的程式碼後發現,語法上沒有任何錯誤。於是我就去Google了一下,在stackoverflow中找到了答案()
https://stackoverflow.com/questions/37849980/openpyxl-no-attribution-error
原來,get_highest_row()和get_highest_column()在最新版的openpyxl模組中已經被刪除了,取而代之的是max_row和max_column兩個方法。
注意:使用的時候不用在方法後面新增括號。