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.
DjangoSnippets - http://djangosnippets.org/snippets/1151/
PyPI - https://pypi.python.org/pypi/django-excel-response/1.0
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', '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', row_merge=True)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-excel-response2-3.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05eade79a5129beefcec4f3f90cd5d7c2540d028f70e788faa39adb50a458e9a |
|
MD5 | 16c12a94b82912d1c8db7c0c0571c762 |
|
BLAKE2b-256 | 4fb94544603894ab350c06876cdb775d43c19ce5304b22e69f74745be81829a7 |
Hashes for django_excel_response2-3.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 864ba614fa42a749fde0079eee1a31525ed68ffa82d683fd933d179e71b12f6d |
|
MD5 | c38bb6e3488613cca059aead9f7d71fd |
|
BLAKE2b-256 | 9c5ac081527179db3b351ae7d5cfb18bf532497b21d24ed6dac301f3d43310e7 |