/Users/zhengyaqi/opt/anaconda3/envs/py/bin/python /Users/zhengyaqi/PycharmProjects/pythonProject13/main.py Traceback (most recent call last): File "/Users/zhengyaqi/PycharmProjects/pythonProject13/main.py", line 32, in <module> find_and_copy_files(source_folder, target_folder, excel_file) File "/Users/zhengyaqi/PycharmProjects/pythonProject13/main.py", line 7, in find_and_copy_files excel_data = pd.read_excel(excel_file, engine='xlrd') File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 478, in read_excel io = ExcelFile(io, storage_options=storage_options, engine=engine) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 1513, in __init__ self._reader = self._engines[engine](self._io, storage_options=storage_options) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_xlrd.py", line 35, in __init__ super().__init__(filepath_or_buffer, storage_options=storage_options) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 540, in __init__ self.book = self.load_workbook(self.handles.handle) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_xlrd.py", line 48, in load_workbook return open_workbook(file_contents=data) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/xlrd/__init__.py", line 170, in open_workbook raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported') xlrd.biffh.XLRDError: Excel xlsx file; not supported报错结果
时间: 2023-07-17 12:07:07 浏览: 197
这个错误是由于 `xlrd` 引擎不支持读取 Excel `.xlsx` 文件引起的。`xlrd` 只支持旧版本的 Excel `.xls` 文件。
为了解决这个问题,你可以尝试使用 `openpyxl` 引擎来读取 `.xlsx` 文件。可以将代码中的 `engine='xlrd'` 修改为 `engine='openpyxl'`,如下所示:
```python
excel_data = pd.read_excel(excel_file, engine='openpyxl')
```
然后重新运行代码,看看是否能够成功读取 Excel 文件。
如果你还没有安装 `openpyxl`,可以在终端中使用以下命令进行安装:
```
pip install openpyxl
```
如果仍然遇到问题,请确保你的 Excel 文件没有损坏,并且使用的是支持的文件格式。
希望这次能够解决你的问题,如果还有其他疑问,请随时向我提问!
阅读全文