openpyxl使用问题——OSError: File contains no valid workbook part

发布时间 2023-09-08 15:07:45作者: Danlis

第一种:打开xls的文件,报错,这个比较容易理解,就是openpyxl是不支持打开xls文件的,版本太老了。推荐使用xlrd库。

openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support the old .xls file format, please use xlrd to read this file, or convert it to the more recent .xlsx file format.

第二种:直接将xls文件的后缀名给改成xlsx的时候,会报下面的错误。

OSError: File contains no valid workbook part

如果文件就是xls的话,那么直接打开,另存为xlsx,这种情况它就不会报错了。