On Aug 20, 2010, at 6:50 AM, Filippo Salvatici wrote:
I am creating a csv file with fastercsv.

require 'fastercsv'
FasterCSV.open("file.csv", "w") do |csv|
 csv << [45678, 45678, "stringa"]
end

I would also print the last cell in quotation marks. Is there anyone who
can help me?


If you look at the spec for CSV, the proper contents of file.csv are:

45678,45678,stringa

You might put quotes around the string, but they are not needed for the file to be valid. However, if you had a comma in the string
  csv << [1,2,"a,b"]
then the file will contain
1,2,"a,b"
so that the comma isn't seen as a value separator.

Be aware that FasterCSV (which is just CSV in Ruby1.9) is quite strict about adherence to the standard and many files that CSV will complain are malformed will be quietly parsed by MS-Excel. (Yes, I know you must be shocked about that ;-)

-Rob

Rob Biedenharn          
[email protected]     http://AgileConsultingLLC.com/
[email protected]               http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to