0

I have a pd.ExcelWriter(path, engine='xlsxwriter') object. When I do df.to_excel(writer) then existing sheets remove. How can I avoid it, i.e. how can I append new sheet using this object?

  • I think you can open the file in append mode and add to it. with open('file.xlsx', 'a') as f: df.to_excel(f, header=False ) – No_body Jan 25 '19 at 16:25

1 Answers1

0

The python package 'xlsxwriter' can't append sheets to an existing Excel file. It is a file writer only. Refer to their FAQ (first question):

https://xlsxwriter.readthedocs.io/faq.html

I would use openpyxl instead: engine='openpyxl' instead of engine='xlsxwriter'. Don't forget to install openpyxl using pip, if you don't already have the package.

  • Thanks for answer! The problem is that I have quite huge amount of code already written using xlsxwriter. When I change engine to openpyxl my code crashes. Maybe there is a way to somehow to avoid rewritting the hole code? – Dmitry Denisov Jan 27 '19 at 13:10