Skip to main content

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

Project description

django-excel-response2

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

django-excel-response

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.

django-excel-response2

When using Tarken’s django-excel-response. We find that Chinese is messed code when we open .xls in Mac OS. As discussed in http://segmentfault.com/q/1010000000095546. 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

Inherit

# 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__))
else:
    ExcelResponse = type('HttpResponse', (http.HttpResponse, ), dict(__init__=__init__))

Installation

pip install django-excel-response2

Usage

from django_excel_response import ExcelResponse

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

or

from django_excel_response import ExcelResponse

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

or

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')

or

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', merge_type='row_merge')

Params

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

CSV

datas = [
    [u'中文', ]
]
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.

Source Distribution

django-excel-response2-3.0.4.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

django_excel_response2-3.0.4-py2.py3-none-any.whl (4.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-excel-response2-3.0.4.tar.gz.

File metadata

File hashes

Hashes for django-excel-response2-3.0.4.tar.gz
Algorithm Hash digest
SHA256 819548f34b5baf43691d1591cfd505bcbfcf9d24c3f33d7f79912ffcaf829bfa
MD5 4225da025fb7cd87ad8ea7622f764877
BLAKE2b-256 9724b2ff456580f1a1919c151717d4c298e17839eb3ab854970a9ebd2c9b97f2

See more details on using hashes here.

File details

Details for the file django_excel_response2-3.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_excel_response2-3.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9a54b7a5ab4e3c12702c3c2f98e534ce3722b44ea2e88e7d96b794ae16624797
MD5 8d99473a6234c8b3bba61a1f1b300b59
BLAKE2b-256 cf3d0bea3abcd83bdbf8aa2859dae091a15fd875ded1f6e23b482916767bc1a5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page