2013-03-22 89 views

回答

0

如果on Rails的使用Ruby,你可以这样做:

require 'csv'  

csv_text = File.read('...') 
csv = CSV.parse(csv_text, :headers => true) 
csv.each do |row| 
    row = row.to_hash.with_indifferent_access 
    YourModel.create!(row.to_hash.symbolize_keys) 
end 
+1

感谢您的帮助,但我从来没有使用过的Ruby,也许有一天我会试一试。暂时,我需要在几天内完成。 – Sonic 2013-03-22 22:43:13

相关问题