本帖最后由 lemon_wb 于 2021-9-23 02:33 编辑
import os
import openpyxl
from openpyxl import workbook
from openpyxl import load_workbook
filepath = 'D:\\test\\2021年1月\\202001历下单户结算'
filelist = os.listdir(filepath)
files=[]
for i in range(len(filelist)):
child = os.path.join('%s\\%s' % (filepath, filelist[i]))
print('%s\\%s' % (filepath, filelist))
wb = openpyxl.load_workbook(child)
返回
D:\Users\test\PycharmProjects\pythonProject1\venv\Scripts\python.exe D:/Users/test/PycharmProjects/pythonProject1/new.py
Traceback (most recent call last):
File "D:/Users/test/PycharmProjects/pythonProject1/new.py", line 14, in <module>
wb = openpyxl.load_workbook(child)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\reader\excel.py", line 318, in load_workbook
data_only, keep_links)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\reader\excel.py", line 126, in __init__
self.archive = _validate_archive(fn)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\reader\excel.py", line 96, in _validate_archive
raise InvalidFileException(msg)
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.
Process finished with exit code 1 |