当我按照书中的方法获取最大行和最大列的时候,出现了下面的错误提醒:
import openpyxlwb = openpyxl.load_workbook('example.xlsx')sheet = wb.get_sheet_by_name('Sheet1')print(sheet.get_highest_row())
D:\>python test.pytest.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两个属性。
注意:使用的时候不用在方法后面添加括号。
联系客服