Skip to main content

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

Metadata

Release files for django-excel-response2 3.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-excel-response2 3.0.6
File Size Uploaded
django-excel-response2-3.0.6.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-excel-response2 3.0.6
File Interpreter ABI Platform
django_excel_response2-3.0.6-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 9.8 kB

Release files / django-excel-response2-3.0.6.tar.gz

Download URL django-excel-response2-3.0.6.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
404b28818a262153559155239b719ba50e3c09484d638acdaadadfb309fc1b56
BLAKE2b-256 checksum
How to use checksums
cbe0e1745ca77f776f330bb0417f2c1f3a90047ab4a55a21b3dbf391562e0e08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / django_excel_response2-3.0.6-py2.py3-none-any.whl

Download URL django_excel_response2-3.0.6-py2.py3-none-any.whl
Size 4.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fe0c54207caf7efefcad689427bffad9209808e6102becb07967d5f8c92b82c7
BLAKE2b-256 checksum
How to use checksums
fd6644986943e506a3d43de4a8515e7c33bf9dbc43a04707097e8fd17aa9792f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

3.0.6 This release

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.1

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page