On Jun 30, 2006, at 5:49 AM, Dave Linger wrote:
> Hello all! I''m just starting with Ruby on Rails and need to ingest
a
> .csv (Excel) file, and use the data it contains to be shown on screen.
> Can anyone show me where to start with this script?
>
> Thanks
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
Hi-
THere is a CSV class in the ruby stdlib. Pretty easy to use. This
ought to get you up and running:
#in foo.csv
foo,bar,baz,123
nik,kop,dur,3,5
one,two,three,9,8,7
four,five,six,7,3,4
# in irb
ez ez $ irb
irb(main):001:0> require ''csv''
=> true
irb(main):002:0> CSV.open(''foo.csv'', ''r'')
do |row|
irb(main):003:1* p row
irb(main):004:1> end
["foo", "bar", "baz", "123"]
["nik", "kop", "dur", "3",
"5"]
["one", "two", "three", "9",
"8", "7"]
["four", "five", "six", "7",
"3", "4"]
=> nil
irb(main):005:0>
Cheers-
-Ezra