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",
)