Incubator-superset: Choose encoding when export csv

Created on 2 Nov 2016  路  12Comments  路  Source: apache/incubator-superset

Is there any plan to add this feature that I can choose encoding when export csv?
Because Excel uses the ansi to open the csv files, Chinese is mess code.

Most helpful comment

We are having issues with csv default encoding (and default separator as well) too.

Would you be interested in a PR that allows to choose csv encoding and separator using the config.py ?

We were thinking about adding two variables in config.py (CSV_SEP and CSV_ENCODING) to be able to change the default way of writing CSV (values would be retrieved when calling to_csv method).

Does it sound right to you ?

All 12 comments

We should just probably export the csv encoded in utf-8. Isn't this the case? If so and excel cannot handle it, that's an excel issue. Btw what do you mean with ansi?

You're right, it's an excel issue. But the truth is, people not familiar with encoding will always use excel to open csv. So I think maybe it's better to let them choose encoding(gbk) which I tell them to when exporting csv.

You can add utf8 file header manually, to tell software decode it with utf8
header = bytes(b'\xEF\xBB\xBF').decode('utf-8')
return Response(
header+payload,
status=200,
headers=generate_download_headers("csv"),
mimetype="application/csv")

PR welcomed!

We are having issues with csv default encoding (and default separator as well) too.

Would you be interested in a PR that allows to choose csv encoding and separator using the config.py ?

We were thinking about adding two variables in config.py (CSV_SEP and CSV_ENCODING) to be able to change the default way of writing CSV (values would be retrieved when calling to_csv method).

Does it sound right to you ?

I tried to adding the CSV_ENCODING in config.py like #3441, In Python3.5 it doesn't work锛宧owever in Python2.7 it works well.
It seems that Pandas IO tool "to_csv" ignores encoding argument in Python3.

Yes I noticed this too ... I am planning on issuing a new PR (today) to fix this using flask Response encoding.

I modify config.py:
CSV_EXPORT = {
'encoding': 'gbk',
}

But it doesn't work.Using vim to view the downloaded file:
fileencoding=utf-8

Do I have an operation in error?

now if you solve this problem? i am in this trouble now. @chengwei1231

now if you solve this problem? i am in this trouble now. @chengwei1231

in /views/core.py, i change Response to CsvResponse.
eg:
response = CsvResponse(csv, mimetype='text/csv')

@chuancyzhang Could you explain more detail? you mean def generate_json??

For those who are still suffering from csv export encoding matters,
Try editting /views/core.py
Look for the term
'Responce(csv,'
You'll find it under def csv.
Add 'Csv' in front of the term to show like
'CsvResponse(csv,'
Save it and add below lines to your Superset_config.py:
CSV_EXPORT = {
'encoding': 'utf_8_sig',
}

The encoding should be changed accodingly to your requirement.
Then run superset init and restart.
Now you should be able to download properly encoded csvs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gbrian picture gbrian  路  3Comments

john-bodley picture john-bodley  路  3Comments

amien90 picture amien90  路  3Comments

sashank picture sashank  路  3Comments

XiaodiKong picture XiaodiKong  路  3Comments