Answer the question
In order to leave comments, you need to log in
How to return result in Excel (Flask) file via AJAX?
The code:
...
cnn.execute(sql)
rec=cnn.fetchall()
strIO = StringIO.StringIO()
strIO.write(excel.make_response_from_array(rec, "xls"))
strIO.seek(0)
return send_file(strIO, mimetype='application/vnd.ms-excel',attachment_filename="result.xls",as_attachment=True)
Answer the question
In order to leave comments, you need to log in
I also tried this option:
...
rec=cnn.fetchall()
response = make_response(excel.make_response_from_array(rec, "xls"))
response.headers['Content-Type'] = 'application/vnd.ms-excel'
response.headers['Content-Disposition'] = 'attachment; filename=result.xls'
return response
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question