Traceback (most recent call last):
File "/Users/long3/workspace/usefullc/electron-xls/backend/test/testXls.py", line 41, in <module>
generate_excel_from_template(template_path, output_path, excel_data)
File "/Users/long3/workspace/usefullc/electron-xls/backend/test/testXls.py", line 6, in generate_excel_from_template
template = load_workbook(template_path)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 344, in load_workbook
reader = ExcelReader(filename, read_only, keep_vba,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 123, in __init__
self.archive = _validate_archive(fn)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 95, in _validate_archive
archive = ZipFile(filename, 'r')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/zipfile.py", line 1269, in __init__
self._RealGetContents()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/zipfile.py", line 1336, in _RealGetContents
raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file
因为自己手动在磁盘中建立一个txt 文件,但是后缀确实xlsx. 导致文件格式不兼容。如下图所示:大小为0
保存的时候还提示不兼容。
后面直接通过wps软件创建xlsx 才正常。