0

I want to get second to fourth column of a Excel file by using Roo::Excel class.

columns = []
columns << Roo::Excel.new("foo.xls").column(2)
columns << Roo::Excel.new("foo.xls").column(3)
columns << Roo::Excel.new("foo.xls").column(4)

I'm writing code redundantly because Roo::Excel.new("foo.xls") itself doesn't return a value even if I wait per minutes, but if I chain the method column() then it returns a Array instantly.

Is there a DRY way to write the code above?

This is the Excel file I'm trying to read.

http://www.tse.or.jp/listing/kessan/b7gje600000057pv-att/kessan10_1121.xls

ironsand
  • 14,329
  • 17
  • 83
  • 176

1 Answers1

1

How about this Ruby's range ?

columns = []
(2..4).each do |r|
 columns << Roo::Excel.new("foo.xls").column(r)
end
Hetal Khunti
  • 787
  • 1
  • 9
  • 23