(self, wb, title="report")
return response
Take a workbook and return a csv file response
Take a workbook and return a csv file response
Take a workbook and return a csv file response
def build_csv_response(self, wb, title="report"):
        """ Take a workbook and return a csv file response """
        title = generate_filename(title, '.csv')
        myfile = StringIO()
        sh = wb.active
        c = csv.writer(myfile)
        for r in sh.rows:
            c.writerow([cell.value for cell in r])
        response = HttpResponse(
            myfile.getvalue(),
            content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename=%s' % title
        response['Content-Length'] = myfile.tell()
        return response
def build_csv_response ( self , wb , title = "report" ) : title = generate_filename ( title , '.csv' ) myfile = StringIO ( ) sh = wb . active c = csv . writer ( myfile ) for r in sh . rows : c . writerow ( [ cell . value for cell in r ] ) response = HttpResponse ( myfile . getvalue ( ) , content_type = 'text/csv' ) response [ 'Content-Disposition' ] = 'attachment; filename=%s' % title response [ 'Content-Length' ] = myfile . tell ( ) return response