Forum: Ruby on Rails How to convert xls to csv?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C42c706fab23da0b6d3cd2cfbb8db27d?d=identicon&s=25 Salil Gaikwad (salil)
on 2009-02-18 05:54
How to access row value using spreadsheet?
How to find last row or end of file using roo?
How to convert xls to csv?
D69d23d8e811e8ab2a8593380d6ede63?d=identicon&s=25 Jeff Emminger (jemminger)
on 2009-02-18 23:22
(Received via mailing list)
google "ruby excel"

On Feb 17, 11:54 pm, Salil Gaikwad <rails-mailing-l...@andreas-s.net>
0d56133042e4814c1b2255ea655f2361?d=identicon&s=25 Jeff Burlysystems (jburly)
on 2009-02-19 01:15
(Received via mailing list)
Hi Salil,

To convert xls to csv and then parse for use in ruby, you could try
wrapping xls2csv (http://www.wagner.pp.ru/~vitus/software/catdoc/) and
parsing via CSV (http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/
index.html), something like:

$ irb
irb(main):001:0> require 'csv'
=> true

irb(main):002:0> csv_raw = `xls2csv test.xls`.sub(/\s+$/, "\n")
=> "\"fruit\",\"color\"\n\"banana\",\"yellow\"\n\"strawberry\",\"red
\"\n\"tangerine\",\"orange\"\n"

irb(main):003:0> CSV.parse(csv_raw) {|rec| puts rec.inspect }
["fruit", "color"]
["banana", "yellow"]
["strawberry", "red"]
["tangerine", "orange"]
=> nil

Jeff

On Feb 17, 8:54 pm, Salil Gaikwad <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.