1. 解析CSV:
(1)读取文件:csv = CSV.read("#{Rails.root}/public/data/statecountycity.csv", :headers => true, :header_converters => lambda{|h| h.strip})
(2)遍历:csv.each do |row| {c_row = row.to_hash ......}
时间: 2024-11-07 15:33:34
1. 解析CSV:
(1)读取文件:csv = CSV.read("#{Rails.root}/public/data/statecountycity.csv", :headers => true, :header_converters => lambda{|h| h.strip})
(2)遍历:csv.each do |row| {c_row = row.to_hash ......}