使用xlrd
读取xlsx文件时,会报错:XLRDError: Excel xlsx file; not supported
from xlrd import open_workbook
th = open_workbook(r'文件.xlsx')
是因为新版的xlrd不支持xlsx
文件,只支持xls
文件,xlrd 已删除了对 xls 文件以外的任何内容的支持。
1.如果想要使用xlrd
读取xlsx
文件,需要安装旧版xlrd
pip install xlrd==1.2.0
但是这种方法会遇到一些其他的问题,会有安全警告,并且在读取excel文件时会报错:
AttributeError: 'ElementTree' object has no attribute 'getiterator'