您的位置:首页 > 编程语言 > Go语言

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: