You must have array of all rows then you can convert it to some hash if you like so.
I would recommend to use a batch_factory
gem.
The gem is very simple and relies on the roo
gem under the hood.
Here is the code example
require 'batch_factory'
factory = BatchFactory.from_file(
Rails.root.join('b.xlsx'),
keys: [:column1, :column2, ..., :what_ever_column_name]
)
Then you can do
factory.each do |row|
puts row[:column1]
end
You can also omit specifying keys
. Then batch_factory
will automatically fetch headers from the first row. But your keys would be in russian. Like
factory.each do |row|
puts row['Товар']
end
If you want to hash with product name as key you can do
factory.inject({}) do |hash, row|
hash.merge(row['Товар'] => row)
end
Rails.root.join('b.xlsx')
. It is much nicer.roo
?roo
it returns me an array,which is useless for meroo
has an option to returns a hash. If each is given a hash with the names of some columns, then each will generate a hash with the columns supplied for each row.