功能分析:
1、生成excel文件;
2、将生成的excel文件下载到本地;
utils.py文件中完成excel文件的数据写入,及生成表格样式设置
import xlwt,datetime
from xlwt import *
# 写入excel文件函数
def wite_to_excel(n,head_data,records,download_url):
#获取时间戳
timestr = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
# 工作表
wbk = xlwt.Workbook()
sheet1 = wbk.add_sheet('sheet1',cell_overwrite_ok=True)
#写入表头
for filed in range(0,len(head_data)):
sheet1.write(0,filed,head_data[filed],excel_head_style())
#写入数据记录
for row in range(1,n+1):
for col in range(0,len(head_data)):
sheet1.write(row,col,records[row-1][col],excel_record_style())
#设置默认单元格宽度
sheet1.col(col).width = 256*15
wbk.save(download_url+'New-'+timestr+'.xls')
return ti
最后
以上就是传统朋友最近收集整理的关于django excel 导出页面_django导出数据生成excel并下载到本地的全部内容,更多相关django内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复