E
E
Emil Revencu2016-01-04 11:22:45
Flask
Emil Revencu, 2016-01-04 11:22:45

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)

The response is not a file, but a string: Response 9728 bytes [200 OK]
How to send the result from Mysql to the client as an Excel file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Emil Revencu, 2016-01-04
@Revencu

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

In the answer krakozyabry

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question