@ferdy , i think i could use some help of yours, if you have time.
I have a data_editor with 7 column, which the last one is enabled to user inputs. And then i have a download button to export all the data_editor in xlsx format. But, when i download it, the data from the last column is always empty. I don’t know if i have to use some kind of session_state or not.
PS: there’s a micro download button icon on the top-right of the table, and when i hit it, it downloads a csv with the data from the last column successfully. I wish i had this answer in the forum, but i just can’t find the solution anywhere.
I’m gonna share this snippet. I just have a dataframe (df9) and i create 3 columns (only the last one, called ‘Encomenda (qtd)’, was created to get users input in a data_editor).
Then, i create the data_editor, disabling all columns but ‘Encomenda (qtd)’.
After this, i just have a snippet to create a download button and export all data.
df9['Objetivo de Vendas 2024'] = round(df9['Vendas (qtd) 2023'] * 1.125)
df9['Vendas (qtd) Previstas Mensualizado'] = round(
df9['Objetivo de Vendas 2024']/12)
df9['Encomenda (qtd)'] = np.nan
st.data_editor(df9,
column_config={
'Encomenda (qtd)': st.column_config.NumberColumn('Encomenda (qtd)'),
'': None
},
disabled=['CNP', 'SIS', 'Marca/Produto',
'Apresentação', 'Vendas (qtd) 2023', 'Objetivo de Vendas 2024', 'Vendas (qtd) Previstas Mensualizado'],
use_container_width=True,
hide_index=True)
def convert_df_to_excel(df):
# Create a BytesIO buffer to save the Excel file
excel_buffer = io.BytesIO()
# Use Pandas to write the DataFrame to the buffer as an Excel file
with pd.ExcelWriter(excel_buffer, engine='xlsxwriter', mode='xlsx') as writer:
df.to_excel(writer, index=False)
return excel_buffer
# Applying the function
excel_budget = convert_df_to_excel(df9)
# download button
colunas_1 = st.columns(6)
colunas_1[4].download_button(
label="Download Budget",
data=excel_budget,
file_name='budget.xlsx',
mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
Thank you in advance for your patience!!