Skip to main content

A function extends of Tarken's django-excel-response

Project description


A subclass of HttpResponse which will transform a QuerySet, or sequence of sequences, into either an Excel spreadsheet or CSV file formatted for Excel, depending on the amount of data. All of this is done in-memory and on-the-fly, with no disk writes, thanks to the StringIO library.


When using Tarken’s django-excel-response. We find that Chinese is messed code when we open .xls in Mac OS. As discussed in We realize django-excel-response2 Based on Tarken’s django-excel-response to solve this problem By adding a Param named font to set font.

At The Same Time:

  • Fix Bug
    • can’t subtract offset-naive and offset-aware datetimes


# Since Version 2.0.2
if 'FileResponse' in names:
    ExcelResponse = type('ExcelResponse', (http.FileResponse, ), dict(__init__=__init__))
elif 'StreamingHttpResponse' in names:
    ExcelResponse = type('StreamingHttpResponse', (http.StreamingHttpResponse, ), dict(__init__=__init__))
    ExcelResponse = type('HttpResponse', (http.HttpResponse, ), dict(__init__=__init__))


pip install django-excel-response2


from django_excel_response import ExcelResponse

def excelview(request):
    objs = SomeModel.objects.all()
    return ExcelResponse(objs)


from django_excel_response import ExcelResponse

def excelview(request):
    data = [
        ['Column 1', 'Column 2'],
        [1, 2],
        [3, 4]
    return ExcelResponse(data, 'my_data', font='name SimSum')


from django_excel_response import ExcelResponse

def excelview(request):
    data = [
        ['Column 1', 'Column 2'],
        [1, [2, 3]],
        [3, 4]
    return ExcelResponse(data, 'my_data', font='name SimSum', row_merge=True)


  • font=’name SimSum’
    • Set Font as SimSum(宋体)
  • force_csv=True
    • CSV Format? True for Yes, False for No, Default is False


  Win Excel 2013 Mac Excel 2011 Mac Excel 2016 Mac Numbers
UTF8 Messy Messy Messy Normal
GB18030 Normal Normal Normal Messy
UTF8 + BOM_UTF8 Normal Messy Normal Normal
UTF16LE + BOM        

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-excel-response2, version 3.0.2
Filename, size File type Python version Upload date Hashes
Filename, size django_excel_response2-3.0.2-py2.py3-none-any.whl (4.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size django-excel-response2-3.0.2.tar.gz (4.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page