I am trying to add sheets to a xlsx file using pandas
and openpyxl
writer = pd.ExcelWriter(save_path, engine='openpyxl')
print(type(book)) # <class 'openpyxl.workbook.workbook.Workbook'>
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
save_output(df, writer, sheet_name)
writer.save()
writer.close()
But the line writer.book = book
is getting AttributeError: can't set attribute 'book'
.
Searching on the web, some answer pop up and that code seems like to be the right way to add a sheet to an excel file.
(ex. How to save a new sheet in an existing excel file, using Pandas? ).
Why do I get that error? How can I get rid of it?