我试图下载一个由XlsxWriter创建的Excel文件,将其作为Flask view的响应发送到AngularJS。但是,当我试图打开该文件时,它显示该文件已损坏。我不知道我错过了什么。请在下面找到我的代码:
XlsGenerator.py:
output = io.BytesIO()
workbook = xlsxwriter.Workbook(output, {'in_memory': True})
# code to add data
workbook.close()
output.seek(0)
response = Response(output.getvalue(), mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
headers={"Content-Disposition": "attachment;filename=Dss_project.txt"},
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
return response
app.js:
也尝试使用send_file()作为替代方法,但它给出了相同的错误!在
send_file(output, attachment_filename='project_data.xlsx',as_attachment=True)
目前没有回答
相关问题 更多 >
编程相关推荐