保存在服务器端
book = xlwt.Workbook(encoding='utf8') # 创建Workbook,相当于创建Excel
sheet = book.add_sheet('Sheet1', cell_overwrite_ok=True)
sheet.write(0, 0, '', styleHead)
book.save('D:\\{}.xlsx'.format(time.strftime('%Y-%m-%d_%H-%M-%S',time.localtime(time.time()))))
浏览器访问下载
book = xlwt.Workbook(encoding='utf8') # 创建Workbook,相当于创建Excel
sheet = book.add_sheet('Sheet1', cell_overwrite_ok=True)
sheet.write(0, 0, '', styleHead)#通过浏览器下载到客户端
book.save(output)output.seek(0)
resp = make_response(output.getvalue())
output.close()#关掉流
resp.headers["Content-Disposition"] = "attachment; filename=aa.xlsx"
resp.headers['Content-Type'] = 'application/x-xlsx'return resp
只是做一个例子,具体表格数据及样式如何设置网上方法很多,随便找,我就不献丑了