0

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?

Kodeeo
  • 139
  • 8
  • 1
    install packages using 'conda install openpyxl' if your environment support. i faced same yesterday using python3.9 but after changing environment and install using conda, then solved – ahmedul Kabir Omi Sep 28 '22 at 17:59

0 Answers0