| Message: 94315 |
 |
BY: rux pin (ruxpin) DATE: 2010-07-23 15:17 SUBJECT: RE: Welcome to Open-Discussion it's easy since you did read the excel file already!
all you need to do is create db model and save it, let's assume you are importing accounts' info from excel
at you controller file
def import_to_DB
your_upload_methods # there goes your upload process
Account.import_from_excel(file_path) #file_path is the path of the file which you just uploaded for import
....
end
then your model file, in this case, Account.rb
require 'spreadsheet'
def self.import_from_excel(file_path)
xlsfile= Spreadsheet.open file_path
sheet = xlsfile.worksheet 0
sheet.each do |row|
Account.create({:email => row[0],
:name => rom[1],
:password => "1111",
:password_confirmation => "1111"})
end
end
you can do more in your import_from_excel method, such as some excel format validations and data validations.
| |