今天开始学习《python编程快速上手》中的第12章:处理Excel电子表格。但是遇到了点小问题。
当我按照书中的方法获取最大行和最大列的时候,出现了下面的错误提醒:
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中找到了答案()
/questions/37849980/openpyxl-no-attribution-error
原来,get_highest_row()和get_highest_column()在最新版的openpyxl模块中已经被删除了,取而代之的是max_row和max_column两个方法。
注意:使用的时候不用在方法后面添加括号。
欢迎关注我公众号【小众技术】,此公众号专注分享Python、爬虫学习资料和干货,关注后回复【PYTHON】,无套路免费送你一个学习大礼包,包括爬虫视频和电子书~
如果觉得《Python错误:AttributeError: 'Worksheet' object has no attribute 'get_highest_row' 解决办法》对你有帮助,请点赞、收藏,并留下你的观点哦!