What's the best way to export UTF8 data into Excel?

前端 未结 8 1512
不思量自难忘°
不思量自难忘° 2020-12-03 03:12

So we have this web app where we support UTF8 data. Hooray UTF8. And we can export the user-supplied data into CSV no problem - it\'s still in UTF8 at that point. The proble

8条回答
  •  盖世英雄少女心
    2020-12-03 03:19

    After struggling with the same problem for a few hours I found this excellent post on the subject

    http://blog.plataformatec.com.br/2009/09/exporting-data-to-csv-and-excel-in-your-rails-app/ quote :

    So, these are the three rules for dealing with Excel-friendly-CSV:

    1. Use tabulations, not commas.
    2. Fields must NOT contain newlines.
    3. Use UTF-16 Little Endian to send the file to the user. And include a Little Endian BOM manually.

    However, if you're using ruby, you problem is solved: first you have the FasterCSV gem

    but i ended up using the spreadsheet gem which directly generates excell spreadsheets (i have link limitation, just google spreadsheet + rubyforge) Brilliant !

提交回复
热议问题