# 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.
* 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': 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', 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
```python
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 | | | | |
Raw data
{
"_id": null,
"home_page": "https://github.com/django-xxx/django-excel-response2",
"name": "django-excel-response2",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "django-excel-response django-excel-response2",
"author": "Hackathon",
"author_email": "kimi.huang@brightcells.com",
"download_url": "https://files.pythonhosted.org/packages/31/fd/4b1b16e7d9f83a2050a81a7c733ca1653bf1048bd27cbc7e0b778b156d41/django-excel-response2-3.0.3.tar.gz",
"platform": null,
"description": "# django-excel-response2\nA function extends of Tarken's django-excel-response\n\n## django-excel-response\n\nA subclass of HttpResponse which will transform a QuerySet,\nor sequence of sequences, into either an Excel spreadsheet or\nCSV file formatted for Excel, depending on the amount of data.\nAll of this is done in-memory and on-the-fly, with no disk writes,\nthanks to the StringIO library.\n\n* DjangoSnippets - http://djangosnippets.org/snippets/1151/\n* PyPI - https://pypi.python.org/pypi/django-excel-response/1.0\n\n## django-excel-response2\n\nWhen using Tarken\u2019s django-excel-response.\nWe find that Chinese is messed code when we open .xls in Mac OS.\nAs discussed in http://segmentfault.com/q/1010000000095546.\nWe realize django-excel-response2 Based on Tarken\u2019s django-excel-response\nto solve this problem By adding a Param named font to set font.\n\nAt The Same Time:\n\n* Fix Bug\n * can't subtract offset-naive and offset-aware datetimes\n\n\n## Inherit\n\n # Since Version 2.0.2\n if 'FileResponse' in names:\n ExcelResponse = type('ExcelResponse', (http.FileResponse, ), dict(__init__=__init__))\n elif 'StreamingHttpResponse' in names:\n ExcelResponse = type('StreamingHttpResponse', (http.StreamingHttpResponse, ), dict(__init__=__init__))\n else:\n ExcelResponse = type('HttpResponse', (http.HttpResponse, ), dict(__init__=__init__))\n\n\n## Installation\n\n pip install django-excel-response2\n\n\n## Usage\n\n from django_excel_response import ExcelResponse\n\n def excelview(request):\n objs = SomeModel.objects.all()\n return ExcelResponse(objs)\n\n\nor\n\n from django_excel_response import ExcelResponse\n\n def excelview(request):\n data = [\n {\n 'Column 1': 1,\n 'Column 2': 2,\n },\n {\n 'Column 1': 3,\n 'Column 2': 4,\n }\n ]\n return ExcelResponse(data, 'my_data', font='name SimSum')\n\n\nor\n\n from django_excel_response import ExcelResponse\n\n def excelview(request):\n data = [\n ['Column 1', 'Column 2'],\n [1, 2],\n [3, 4]\n ]\n return ExcelResponse(data, 'my_data', font='name SimSum')\n\n\nor\n\n from django_excel_response import ExcelResponse\n\n def excelview(request):\n data = [\n ['Column 1', 'Column 2'],\n [1, [2, 3]],\n [3, 4]\n ]\n return ExcelResponse(data, 'my_data', font='name SimSum', row_merge=True)\n\n\n## Params\n\n * font='name SimSum'\n * Set Font as SimSum(\u5b8b\u4f53)\n * force_csv=True\n * CSV Format? True for Yes, False for No, Default is False\n\n\n## CSV\n\n ```python\n datas = [\n [u'\u4e2d\u6587', ]\n ]\n ```\n\n| | Win Excel 2013 | Mac Excel 2011 | Mac Excel 2016 | Mac Numbers |\n| --------------- | :------------: | :------------: | :------------: | :---------: |\n| UTF8 | Messy | Messy | Messy | Normal |\n| GB18030 | Normal | Normal | Normal | Messy |\n| UTF8 + BOM_UTF8 | Normal | Messy | Normal | Normal |\n| UTF16LE + BOM | | | | |\n",
"bugtrack_url": null,
"license": "",
"summary": "A function extends of Tarken's django-excel-response",
"version": "3.0.3",
"split_keywords": [
"django-excel-response",
"django-excel-response2"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "0780d3a6e2c2bb9095add2f2bd475259",
"sha256": "af192b5476aaa8ec63775b91ba6803a33d153ba59c69f6ec4d6c3b1a52aa21f6"
},
"downloads": -1,
"filename": "django_excel_response2-3.0.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "0780d3a6e2c2bb9095add2f2bd475259",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 4573,
"upload_time": "2022-12-09T07:54:03",
"upload_time_iso_8601": "2022-12-09T07:54:03.794584Z",
"url": "https://files.pythonhosted.org/packages/92/c4/344b202bd3c2b223aed05c015ec5e88dfca6196883845bfbc031e8f75b78/django_excel_response2-3.0.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "df144e56c665dca9287a791dff697985",
"sha256": "864d5f8e384d52156e0668550ed210ed4901831682e09a304ca22550d887aae6"
},
"downloads": -1,
"filename": "django-excel-response2-3.0.3.tar.gz",
"has_sig": false,
"md5_digest": "df144e56c665dca9287a791dff697985",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3878,
"upload_time": "2022-12-09T07:54:05",
"upload_time_iso_8601": "2022-12-09T07:54:05.838148Z",
"url": "https://files.pythonhosted.org/packages/31/fd/4b1b16e7d9f83a2050a81a7c733ca1653bf1048bd27cbc7e0b778b156d41/django-excel-response2-3.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-09 07:54:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "django-xxx",
"github_project": "django-excel-response2",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-excel-response2"
}