macro_template_path = r'C:\Users\baphuoc.phamhoang\Box\developement\Streamlit_Dashboards\dashboards\Dashboard.xlsx' with open(macro_template_path, 'rb') as f: buffer = BytesIO(f.read()) with pd.ExcelWriter(buffer, engine="openpyxl", mode="a", if_sheet_exists="replace") as writer: macro_res_2days_df.to_excel(writer, 'input_data', index=False) temporarylocation=r"C:\Users\baphuoc.phamhoang\Box\developement\Streamlit_Dashboards\dashboards\ran_capactiy_dashboard\macro_db_testout.xlsx" with open(temporarylocation, 'wb') as out: out.write(buffer.getvalue()) buffer.close()