Python 下载excel

论坛 期权论坛 脚本     
匿名技术用户   2020-12-29 07:37   86   0

上面源码

View:result_list是一个list为数据,当为list时,用enumerate可以获取到list的值和值所在序号
xlsx = openpyxl.Workbook()
table = xlsx.active
table.title = 'data'
for row_index, line in enumerate(result_list):
    table.append(line)

xlsxfile = io.BytesIO()
xlsx.save(xlsxfile)
return HttpResponse(xlsxfile.getvalue(),
    content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')

URL:注意必须指定文件格式,以及文件名字。
url(r'^file_down/alldatas.xlsx', File_Down, name= 'file_down')

模板:
<a id="downfile" href="{% url 'file_down' %}"> 

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP