igorkasyanchuk / rails_db

Rails Database Viewer and SQL Query Runner
https://www.railsjazz.com/
MIT License
1.46k stars 111 forks source link

Export to CSV - UTF8 encoding #121

Closed benj-p closed 3 years ago

benj-p commented 3 years ago

This gem is amazing, thank you so much!

I noticed one issue with the CSV export feature with special characters such as é, è, à, etc. When I open the CSV file with Excel these special characters are not rendered correctly (é => √©, è => √®, à => √†)

May I suggest that you try to force UTF-8 encoding as such?

def csv
  send_data(@sql_query.to_csv.encode("UTF-8"), type: 'text/csv; charset=utf-8; header=present', filename: 'results.csv')
end

Thanks!

benj-p commented 3 years ago

I realized that the issue was not with the exported file but with the way Excel was handling it. Anyway, thanks a ton for this gem 💎

igorkasyanchuk commented 3 years ago

👍