I have an xlsx template that contains a dashboard on the first page which reads in data from several sheets. My goal is to write into these sheets without replacing the content of the other sheets/dashboard. My code is as follows:
import os
import pandas as pd
import openpyxl
dataframe1 = pd.read_excel('df1.xlsx')
dataframe2 = pd.read_excel('df2.xlsx')
with pd.ExcelWriter('template.xlsx', mode='a', engine = 'openpyxl') as
writer:
dataframe1.to_excel(writer, sheet_name='sheet10')
dataframe2.to_excel(writer, sheet_name='sheet11')
writer.save()
writer.close()
Unfortunately, this results in my template being replaced by only those two sheets, instead of them being appended to the file.