Ruby, csv and excell files
January 19, 2010 – 7:58 amClassic problem, you need to generate some kind of backup file for your data in your application.
Knowing Excell is as closed a format as the vaults of the CIA unless you sell your soul, you run for csv.
You find the gem Faster CSV, generate your data, export, …. and open the generated .csv file with your copy of Excell
and of course it does not work (what else can you expect from the big M ?)
All the accented caraters are transformed into gibberish.
So you google around and learn that to generate an Excell compatible csv file you have to lose a few more hours of work to Microsoft, but somehow you knew that already, (IE6 anyone ?)
Great explanation on the Plataforma blog
Exporting data to CSV and Excel in your Rails apps
Simply put :
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 your troubles are over. The gem to rule them all exists, it is named “Spreadsheet”
Spreadsheet ruby gem
You might want to check out also
csv builder
and of course for all that to work you need the iConv gem
Iconv
Tags: csv, csv builder, excell, fastercsv, iconv, ruby, spreadsheet, xls
CTO of