Django Excel
2015-10-30 00:25
393 查看
def excel_ajax(request):
response = HttpResponse()
response['Content-Disposition'] = 'attachment;filename=export_agencycustomer.xls'
wb = xlwt.Workbook(encoding='utf-8')
sheet = wb.add_sheet(u'订单')
my_time = []
guang = []
for i in SensorData.objects.filter(collertor_id=2):
my_time.extend([i.sensor_time])
guang.extend([i.sensor_guang])
# 处理对应数据获取json格式
data = [1, 2, 3, 4, 5, 6, 7]
List = {'my_time': my_time,
'guang': 2}
# 1st line
sheet.write(0, 0, '光照')
sheet.write(0, 1, '时间')
sheet.write(0, 2, '温度')
sheet.write(0, 3, '湿度')
List = []
row = 1
for i in guang:
sheet.write(row, 0, i) # 此处是在第一列添加数据
# sheet.write(row,1, '测试1')#此处在第二列添加数据
# sheet.write(row,2,'测试2')#此处在第二列添加数据
# sheet.write(row,3,'测试3')#此处在第二列添加数据
row = row + 1
output = StringIO.StringIO()
wb.save(output)
output.seek(0)
response.write(output.getvalue())
return response
response = HttpResponse()
response['Content-Disposition'] = 'attachment;filename=export_agencycustomer.xls'
wb = xlwt.Workbook(encoding='utf-8')
sheet = wb.add_sheet(u'订单')
my_time = []
guang = []
for i in SensorData.objects.filter(collertor_id=2):
my_time.extend([i.sensor_time])
guang.extend([i.sensor_guang])
# 处理对应数据获取json格式
data = [1, 2, 3, 4, 5, 6, 7]
List = {'my_time': my_time,
'guang': 2}
# 1st line
sheet.write(0, 0, '光照')
sheet.write(0, 1, '时间')
sheet.write(0, 2, '温度')
sheet.write(0, 3, '湿度')
List = []
row = 1
for i in guang:
sheet.write(row, 0, i) # 此处是在第一列添加数据
# sheet.write(row,1, '测试1')#此处在第二列添加数据
# sheet.write(row,2,'测试2')#此处在第二列添加数据
# sheet.write(row,3,'测试3')#此处在第二列添加数据
row = row + 1
output = StringIO.StringIO()
wb.save(output)
output.seek(0)
response.write(output.getvalue())
return response
相关文章推荐
- LogoView加载图片的设置及跳转
- 如何离线阅读Google SDK帮助文档
- 查看各个release版本 golang的改动
- The Books I Had Read Some Time Ago
- 谷歌应用商店Google Play重返中国的影响
- 谷歌应用商店Google Play重返中国的影响
- polygon
- golang ftp客户端示例 支持断点续传
- GO语言开源项目
- 深入解析Go语言中for循环的写法
- google浏览器保存密码和保存cookie问题
- 基于Eclipse的Go语言可视化开发环境
- 简介Go语言中的select语句的用法
- 上google搜索
- 深入剖析Go语言编程中switch语句的使用
- Go语言中的if条件语句使用详解
- Google开源基于Deep Learning的word2vec工具
- Google开源的Deep-Learning项目word2vec处理中文
- How to Generate a Good Word Embedding?
- mongo3安装配置系统服务