Skip to main content

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

Project description

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 excel_response2 import ExcelResponse

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

or:

from excel_response2 import ExcelResponse

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

Params

  • font=’name SimSum’
    • Set Font as SimSum(宋体)

  • force_csv=True
    • CSV Format? True for Yes, False for No, Default is False

CSV

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-2.0.9.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

django_excel_response2-2.0.9-py2.py3-none-any.whl (3.8 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: django-excel-response2-2.0.9.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for django-excel-response2-2.0.9.tar.gz
Algorithm Hash digest
SHA256 6066e032e52339077d903028b20e72268addc7e6f3d3ae70854c633a8f97b471
MD5 6c6736eca2e68ec5871f87a8006c4805
BLAKE2b-256 2b517de9f120fc138d40153b6e597abab0f534cd2dbb5186a8afe79b44446c66

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_excel_response2-2.0.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for django_excel_response2-2.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 30d8607a00965e69d07eafdba87ef61509a37a8583f6c33ab7c21fb554114623
MD5 4ecbd16938023f37cead6a3af68e8d24
BLAKE2b-256 bcd3721a60612741d92748fb38b4d048bd4ac3a9dd1569197035b12112589793

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