0

i m trying to add a pandas data frame to create a new sheet in an existing excel workbook. it either deletes the workbook and just saves the data frame or it just does not work and it gives me weird errors. "BadZipFile: File is not a zip file" i m not using zip files . here is my code :

import pandas

` from openpyxl import load_workbook

book = load_workbook(target)
writer = pandas.ExcelWriter(target, engine='openpyxl') 
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)

view.to_excel(writer, "FCST Aug 2022")
writer.save()
vanetoj
  • 103
  • 11
  • An Excel file is a zip file. Also, there are many questions here on SO dealing with this error. – BigBen Aug 24 '22 at 20:56
  • none of them work – vanetoj Aug 24 '22 at 20:58
  • Dang, I had a sick solution to this but the question got closed while I was typing it – smichael_44 Aug 24 '22 at 21:01
  • @smichael_44 - maybe you should post it in one of the linked threads, *assuming it hasn't been suggested already in them*. There are already many questions asking how to do this. No need to create yet more duplicates. – BigBen Aug 24 '22 at 21:02
  • @BigBen it definitely was not posted when I was looking because I essentially had the same question a year ago, i'll take a look at some threads and see if there is anything new that I haven't seen, thank you – smichael_44 Aug 24 '22 at 21:04
  • And of course you're free to leave a link here to the answer you post... – BigBen Aug 24 '22 at 21:06
  • @vanetoj I posted my solution here: https://stackoverflow.com/a/73479475/18784484 – smichael_44 Aug 24 '22 at 21:09

0 Answers0