Hello, we have a streamlit app which upload an excel file process it using the format like colours of the cells and download another excelfile.
Expected behavior:
Currently we do not find a way to mantain the formats when we use uploader tool. The result is a BytesIO object but we can not transform it to a workbook openpyxl with the formats.
Actual behavior:
Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.
Saving the workbook to a file with a hardcoded name is dangerous because there will be a race condition with two or more simultaneous sessions. The openpyxl docs say you can use a NamedTemporaryFile to save to a memory buffer. I tried that in Windows and it didn’t work, I guess because the code tries to open the same file twice.
What I do is passing the buffer to wb.save()
import io
# Your code here: load the workbook and process it.
# ...
buffer = io.BytesIO()
wb.save(buffer)
st.download_button(
label="Download Excel worksheet without index",
data=buffer,
file_name="fk.xlsx",
)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.