You can put the xls file into /tmp directory. Then put gem spreadsheet into your Gemfile. Then create xls.rb class into lib with a read method.
class Xls
require 'spreadsheet'
def self.read file_path
Spreadsheet.open(file_path) do |book|
book.worksheets.each do |ws|
0.upto ws.last_row_index do |index|
row = ws.row(index)
yield ws, row
end
end
end
end
end
Then, into your task..
namespace :project do
desc "Load xls"
task :load => :environment do
Xls.read("xls_file_path") do |sheet, row|
state = row[0] #row[0] = the first column of the this row.
YourModel.save(state: state)
end
end
end