【发布时间】:2021-09-28 19:44:38
【问题描述】:
单击下载按钮后,我尝试将多个破折号数据表下载到不同工作表上的一个 excel 文件中。我有一个回调,在不同的点击时,执行一些计算并将数据帧返回到破折号数据表。我想获取这些表(在执行计算之后)并导出到一个 excel 文件。注意:我无法使用 dcc.download 下载新版本的 dash,无法访问扩展。这就是为什么我试图通过 pandas 来做到这一点。
下面的数据框(“Investment_To_Gross_Impact”等)表示执行计算后的新数据表。
#download to xsxl
@CAD.callback(
Output('download', 'data'),
Input('download', 'n_clicks'),
Input("titleinput", "value"),
Input('Investment_To_Gross_Impact','data'),
Input('Investment_From_Gross_Impact','data'),
Input('Investment_To_Assumptions','data'),
Input('Investment_From_Assumptions','data'),
)
def export(n_clicks, value, invto, invfrom, ato, afrom ):
df1= pd.DataFrame.from_dict(invto)
df2= pd.DataFrame.from_dict(invfrom)
df3= pd.DataFrame.from_dict(ato)
df4= pd.DataFrame.from_dict(afrom)
if n_clicks>0:
with pd.ExcelWriter(str(value)+'.xlsx', engine='xlsxwriter') as writer:
df1.to_excel(writer, sheet_name='Inv To Gross Impact')
df2.to_excel(writer, sheet_name='Inv From Gross Impact')
df3.to_excel(writer, sheet_name='Inv To Assumptions')
df4.to_excel(writer, sheet_name='Inv From Assumptions')
writer.save()
【问题讨论】:
标签: python pandas dataframe plotly-dash