0

I want to export a pandas dataframe to an existing workbook but it is actually overwritting the existing sheet. I want the dataframe to be exported to a new sheet keeping all other existing sheets in the workbook intact.

Below is the code I tried:

path = r'C:\...\myworkbook.xlsx'
with pd.ExcelWriter(path, mode = 'a', engine = 'openpyxl', date_format = "YYYY-MM-DD") as writer:
     df.to_excel(writer, sheet_name = "new', index = False)

Also the date formatting is not working. Any help would be much appreciated, thanks!

aseb
  • 27
  • 3
  • if you already have sheet with name `new` then you have to use different name for sheet. I tested code on Linux and it gives me new sheet when I use new name, – furas Oct 19 '22 at 15:20
  • Try looking at [How to save a new sheet in an existing file, using Pandas?](https://stackoverflow.com/questions/42370977/how-to-save-a-new-sheet-in-an-existing-excel-file-using-pandas) – Alias Cartellano Oct 19 '22 at 20:32

0 Answers0