Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. def write_status_to_excel(self, request, queryset):
  2. from openpyxl import Workbook
  3. #create workbook
  4. #.....
  5. module_dir=os.path.dirname(__file__)
  6. dname=r'testfile.xlsx'
  7. file_path=os.path.join(module_dir,dname)
  8. workbook.save(filename = file_path)
  9.  
  10. f = open(file_path, 'r')
  11. response = HttpResponse(f, content_type='application/vnd.ms-excel')
  12. #response = HttpResponse(f, content_type='text/csv') #tried this too
  13. response['Content-Disposition'] = 'attachment; filename=%s' % os.path.split(file_path)[-1]
  14. return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement