Comments (7)
@app.route("/download_file_named_in_unicode_csv", methods=['GET'])
def download_file_named_in_unicode():
test_list = [['名字', '分数'], [1, 2], [3, 4], [5.0, 6.1], ["A", "B"], ['名字1', '分数2'], [1, 2], [3, 4], [5.0, 6.1],
["A", "B"]]
return excel.make_response_from_array(test_list, "csv", file_name=u"中文文件名", encoding="ansi")
Traceback (most recent call last):
File "D:\Python27\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "D:\Python27\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "D:\Python27\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "D:\Python27\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "D:\Python27\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "D:/myself/test/flask_excel_quick_start.py", line 189, in download_file_named_in_unicode_xls
return excel.make_response_from_array(test_list, "xls", file_name=u"xls涓枃鏂囦欢鍚?)
File "D:\Python27\lib\site-packages\pyexcel_webio\__init__.py", line 370, in make_response_from_array
file_stream = pe.save_as(array=array, dest_file_type=file_type, **keywords)
File "D:\Python27\lib\site-packages\pyexcel\core.py", line 83, in save_as
return sources.save_sheet(sheet, **dest_keywords)
File "D:\Python27\lib\site-packages\pyexcel\internal\core.py", line 43, in save_sheet
return _save_any(a_source, sheet)
File "D:\Python27\lib\site-packages\pyexcel\internal\core.py", line 55, in _save_any
a_source.write_data(instance)
File "D:\Python27\lib\site-packages\pyexcel\plugins\sources\output_to_memory.py", line 38, in write_data
self._content, sheet, **self._keywords
File "D:\Python27\lib\site-packages\pyexcel\plugins\renderers\excel.py", line 35, in render_sheet_to_stream
file_stream, sheet, file_type=self._file_type, **keywords
File "D:\Python27\lib\site-packages\pyexcel\plugins\renderers\excel.py", line 28, in render_sheet_to_file
save_data(file_name, data, **keywords)
File "D:\Python27\lib\site-packages\pyexcel_io\io.py", line 127, in save_data
**keywords
File "D:\Python27\lib\site-packages\pyexcel_io\io.py", line 144, in store_data
writer.write(data)
File "D:\Python27\lib\site-packages\pyexcel_io\book.py", line 57, in __exit__
self.close()
File "D:\Python27\lib\site-packages\pyexcel_xls\xlsw.py", line 93, in close
self.work_book.save(self._file_alike_object)
File "D:\Python27\lib\site-packages\xlwt\Workbook.py", line 710, in save
doc.save(filename_or_stream, self.get_biff_data())
File "D:\Python27\lib\site-packages\xlwt\Workbook.py", line 674, in get_biff_data
shared_str_table = self.__sst_rec()
File "D:\Python27\lib\site-packages\xlwt\Workbook.py", line 636, in __sst_rec
return self.__sst.get_biff_record()
File "D:\Python27\lib\site-packages\xlwt\BIFFRecords.py", line 77, in get_biff_record
self._add_to_sst(s)
File "D:\Python27\lib\site-packages\xlwt\BIFFRecords.py", line 92, in _add_to_sst
u_str = upack2(s, self.encoding)
File "D:\Python27\lib\site-packages\xlwt\UnicodeUtils.py", line 50, in upack2
us = unicode(s, encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)
127.0.0.1 - - [31/Oct/2018 18:38:05] "GET /download_file_named_in_unicode_xls HTTP/1.1" 500 -
from flask-excel.
Solution: test_list_utf8 = [[u'名字', u'分数'], [1, 2], [3, 4], [5.0, 6.1], [u"A", u"B"], [u'名字1', u'分数2'], [1, 2], [3, 4], [5.0, 6.1],[u"A", u"B"]]
from flask-excel.
Aha! you are using python 2.
Alternatively, you can insert the following to the beginning of your file:
#coding=utf-8
from __future__ import unicode_literals
Or use python 3.
from flask-excel.
Thanks
from flask-excel.
I use python3.7 respond can be made, but chinese characters are still wrong in the excel file
I use make_response_from_array
from flask-excel.
excel.make_response_from_array(result, "xlsx", file_name="中文_" + str_date)
use xlsx !
from flask-excel.
from flask-excel.
Related Issues (20)
- Only in wsgi environment, occur response type error HOT 3
- How can I make the query result collection incrementally join the file stream of the flask-excel interface HOT 2
- docs build failure
- Where does Flask-Excel save uploaded file? HOT 2
- How can I used make_response_from_query_sets() where column_names change to new name HOT 3
- Sheet: Category does not match any given tables.Please be aware of case sensitivity. HOT 3
- csv utf8-sig HOT 1
- auto_commit=False in save_to_database and save_book_to_database to allow rollback HOT 3
- IndexError: Index out of range HOT 2
- AttributeError: 'Request' object has no attribute 'get_array' HOT 1
- Interoperability with uWSGI? HOT 8
- How to change the sheet name when using make_response() (or its variants) HOT 2
- Multiple Sheet using Flask Excel HOT 1
- Update existing rows in database HOT 1
- Export Template HOT 1
- New Line HOT 1
- write a csv file using semicolon as delimiter HOT 1
- make_response_from_records sorts keys
- AttributeError for quickstart sample
- SQLAlchemy's Enum-Type unsupported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-excel.