rails 中使用roo读取excel数据

 

在gemfile 文件中添加

gem 'roo', "1.9.5"

gem 'rubyzip', '< 1.0.0'

注意指定版本

rubyzip需小雨1.0.0,否则会报错:

cannot load zip/zipfilesystem

读取excel文件:

oo = Excelx.new('price_trends_file/'+ file_name)

读取列名:

oo.first_column.upto(oo.last_column) do |col|

  puts oo.cell(1, col).strip

end

读取指定单元格数据

puts oo.cell(line, 列名).to_s.strip

 

 

你可能感兴趣的:(Excel,zip,roo)