I created the test.xlsx with xlwt and wanted to add sheet using the
def write(pureList,resultList,outPath,sheetName):
d = {'words':pureList,'translated':resultList}
df = pd.DataFrame(data=d)
with pd.ExcelWriter(outPath,mode='a',engine="openpyxl") as writer:
df.to_excel(writer,sheet_name=sheetName)
And here is the Error:
Traceback (most recent call last):
File "d:\ori-desktop\exe\python\pandas\21excelwrite.py", line 25, in <module>
write(pureList,resultList,outPath,sheetName)
File "d:\ori-desktop\exe\python\pandas\21excelwrite.py", line 14, in write
with pd.ExcelWriter(outPath,mode='a',engine="openpyxl") as writer:
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\excel\_openpyxl.py", line 73, in __init__
self._book = load_workbook(self._handles.handle, **engine_kwargs)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\openpyxl\reader\excel.py", line 315, in load_workbook
reader = ExcelReader(filename, read_only, keep_vba,
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\openpyxl\reader\excel.py", line 124, in __init__
self.archive = _validate_archive(fn)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\openpyxl\reader\excel.py", line 96, in _validate_archive
archive = ZipFile(filename, 'r')
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python310\lib\zipfile.py", line 1267, in __init__
self._RealGetContents()
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python310\lib\zipfile.py", line 1334, in _RealGetContents
raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file
I want to know how to deal this.