/ Published in: Ruby
Shows how to read/write fully formatted CSV with Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#require 'csv' require 'rubygems' require 'fastercsv' FCSV { |out| out << [:Number,:One,:Two,:Three,:Four] out << [1,"first","second","Third one quoted with a, comma","fourth \"double quotes\"\n line break"] out << [2,"erst","zweite","Dritte,mit Komma","viertl"] out << [3,"primero","segundo","tercero","cuarto,con la coma"] } FasterCSV.foreach("sample.csv", {:headers=>true}) { |r| puts "#{r.length} fields: >>#{r.inspect}<<" r.each { |header, value| puts "\t#{header}=#{value}" } }