Save data to excel file with openpyxl, and an error is reported: badzipfile: file is not a zip file
If the saved file does not exist, use pd.excelwriter directly
If the saved file already exists, use The openpyxl.load_workbook loads the existing file, and then uses pd.excelwriter
If the order of pd.excelwriter and openpyxl.load_workbooks is reversed, an error is reported: badzipfile: file is not a zip file
def append2sheet(filename,data): if not os.path.exists(file_name): ew = pd.ExcelWriter(file_name) data.to_excel(ew,sheet_name = 'sheet1') ew.save() else: wb = load_workbook(file_name) ew = pd.ExcelWriter(file_name) ew.book = wb data.to_excel(ew,sheet_name = 'new') ew.save()
Similar Posts:
- Python: How to Batch Read the Form Information in Word and output them to Excel file
- Problems and solutions of typeerror: ‘generator’ object is not subscriptable in openpyxl
- Python Pandas: Read_Excel() and to_Excel() function
- Python FAQ – error using openpyxl module: zipfile.BadZipFile : File is not a zip file
- Python uses xlwt length limit to report errors
- [Solved] Java read excel file unable to recognize ole stream error
- [Solved] Changing the selected file Error when uploading excel file. Net:: err_UPLOAD_FILE_CHANGED
- Beyond compare is an Excel to TXT script to solve the problems of special characters unable to output, multiple sheet pages unable to compare, and files too large to exceed the system memory
- Preservation and recovery of TF. Train. Saver () model of tensorflow
- The problem of error reporting when importing openpyxl from Python has finally been solved