GithubHelp home page GithubHelp logo

Comments (7)

aleimu avatar aleimu commented on July 17, 2024
@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.

aleimu avatar aleimu commented on July 17, 2024

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.

chfw avatar chfw commented on July 17, 2024

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.

aleimu avatar aleimu commented on July 17, 2024

Thanks

from flask-excel.

tidetam avatar tidetam commented on July 17, 2024

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.

aleimu avatar aleimu commented on July 17, 2024

excel.make_response_from_array(result, "xlsx", file_name="中文_" + str_date)
use xlsx !

from flask-excel.

tidetam avatar tidetam commented on July 17, 2024

from flask-excel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.