import xlwt,StringIo
def dumpData(request):
#获取数据
activitys = Activity.objects.all().order_by('id')
if activitys:
#创建workbook对象并设置编码
ws = xlwt.Workbook(encoding='utf-8')
w = ws.add_sheet(u'评论完成',cell_overwrite_ok=True)
w.write(0, 0, u"订单编号")
w.write(0, 1, u"买家")
w.write(0, 2, u"购买时间")
w.write(0, 3, u"付款金额")
w.write(0, 4, u"提交订单号")
w.write(0, 5, u"返现金额")
w.write(0, 6, u"状态")
excel_row = 1
for activity in activitys:
id = activity.id
buyer = activity.buyer.buyer.username
time = activity.time
price = activity.pay
orderId = activity.orderId
payBack = activity.payBack
status = activity.status
w.write(excel_row, 0, id)
w.write(excel_row, 0, buyer)
w.write(excel_row, 0, time)
w.write(excel_row, 0, price)
w.write(excel_row, 0, orderId)
w.write(excel_row, 0, payBack)
w.write(excel_row, 0, status)
excel_row += 1
exist_file = os.path.exists('test.xls')
if exist_file:
os.remove(r'test.xls')
ws.save('test.xls')
#返回文件给客户
sio = StringIO.StringIO()
ws.save(sio)
sio.seek(0)
response = HttpResponse(sio.getvalue(), content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=test.xls'
response.write(sio.getvalue())
return response

最新文章

  1. C和指针 第十五章 习题
  2. Life Is A Funny Proposition After All
  3. IP地址的分类
  4. Python2.6下基于rsa的加密解密
  5. 能够提高开发效率的Eclipse实用操作
  6. C++的函数重载 转
  7. 自定义的string类
  8. Android基础-EditText键盘的显示与隐藏
  9. [LeetCode234]Palindrome Linked List
  10. phpmyadmin导出数据中文乱码问题
  11. 笔记:Ubuntu 上的Testlink 部署
  12. SQL编程的一些良好好习惯
  13. 2017寒假零基础学习Python系列之函数之 函数之定义可变参数
  14. javascript中的内存管理和垃圾回收
  15. Android布局:宽度适应的横向跟随,防止挤掉重要视图
  16. Centos下搭建golang环境
  17. python unnitest 经验总结
  18. SVN —— 如何设置代理
  19. html头标签meta实现refresh重定向
  20. The Startup Manager FAQ

热门文章

  1. CSU-2221 假装是区间众数(ST表模版题)
  2. Leetcode 557.反转字符串中的单词III
  3. Android获取系统时间yyyyMMddHHmmssSSS
  4. 【bzoj3295】[Cqoi2011]动态逆序对 线段树套SBT
  5. centos6.5 mysql忘记登入密码
  6. HDU 3792 素数打表
  7. 洛谷P2866 [USACO06NOV]糟糕的一天Bad Hair Day
  8. express中放置静态文件
  9. 比较全的.NET页面缓存技术文章
  10. Iframe载入页面 及 跳转页面