Download Button with Excel File

Hi @user-3135 :wave:

Hereโ€™s a reproducible example that uses st.download_button to download an Excel workbook written to an in-memory string with BytesIO:

import streamlit as st
import xlsxwriter
from io import BytesIO

output = BytesIO()

# Write files to in-memory strings using BytesIO
# See: https://xlsxwriter.readthedocs.io/workbook.html?highlight=BytesIO#constructor
workbook = xlsxwriter.Workbook(output, {'in_memory': True})
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello')
workbook.close()

st.download_button(
    label="Download Excel workbook",
    data=output.getvalue(),
    file_name="workbook.xlsx",
    mime="application/vnd.ms-excel"
)

You should be able to adapt this example to your use-case. :slightly_smiling_face: Let us know if you run into roadblocks!

Happy Streamlit-ing! :balloon:
Snehan

3 Likes