【发布时间】:2021-05-11 18:41:36
【问题描述】:
我们编写了将文件从 json 格式转换为 excel 格式的代码,并返回了 excel 文件,就好像我试图打开它损坏的文件一样。
我们已经尝试过 pandas 和 openpyxl 来转换 json。 以下是尝试检查一切是否正常的示例代码。
from flask import request, send_from_directory
df1 = pd.DataFrame([['a', 'b'], ['c', 'd']], index=['row 1', 'row 2'], columns=['col 1', 'col 2'])
df1.to_excel('/tmp/output.xlsx')
return send_from_directory('/tmp/', 'output' + '.xlsx', as_attachment=True)```
Notes: The code has been deployed using kubernetes, we have copied the generated file from the volume and its looking good, while transferring its getting corrupted. And we have tried different content types as well.
【问题讨论】:
标签: pandas flask openpyxl sendfile