def xlsx_to_response(wb, filename):
    f = tempfile.TemporaryFile()
wb._save(f)
f.seek(0)
response = send_file(f, as_attachment=True, attachment_filename=filename,
    add_etags=False)
f.seek(0, os.SEEK_END)
size = f.tell()
f.seek(0)
response.headers.extend({'Content-Length': size, 'Cache-Control': 'no-cache'})
return response
How to clean up temporary file used with send_file?