Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose encoding when export csv #1519

Closed
kylozw opened this issue Nov 2, 2016 · 14 comments · Fixed by #3484 or #3441
Closed

Choose encoding when export csv #1519

kylozw opened this issue Nov 2, 2016 · 14 comments · Fixed by #3484 or #3441

Comments

@kylozw
Copy link

kylozw commented Nov 2, 2016

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.

@xrmx
Copy link
Contributor

xrmx commented Nov 2, 2016

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?

@kylozw
Copy link
Author

kylozw commented Nov 2, 2016

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.

@HugoPu
Copy link

HugoPu commented Feb 28, 2017

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")

@mistercrunch
Copy link
Member

PR welcomed!

@JulieRossi
Copy link
Contributor

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 ?

@ashdaka
Copy link

ashdaka commented Sep 18, 2017

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

@JulieRossi
Copy link
Contributor

JulieRossi commented Sep 18, 2017

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

@chengwei1231
Copy link

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?

@wutengyue
Copy link

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

@chuancyzhang
Copy link
Contributor

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')

@ohoroyoi
Copy link

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

@fortmate
Copy link

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.

@andrey-mikhailov
Copy link

It was useful for me to change default delimiter to ;

    CSV_EXPORT = {
      "encoding": "utf_8_sig",
      "sep": ";"
    }

It allows to import CSV to MS Excel without any additional actions

@alinasrullayev
Copy link

It was useful for me to change default delimiter to ;

    CSV_EXPORT = {
      "encoding": "utf_8_sig",
      "sep": ";"
    }

It allows to import CSV to MS Excel without any additional actions

Encoding option was really useful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet