Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread
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.


Thread View

Thread Author Date
Welcome to Open-DiscussionTom Copeland2007-05-26 19:44
      RE: Welcome to Open-DiscussionVishal Mittal2010-07-19 17:29
            RE: Welcome to Open-Discussionrux pin2010-07-21 09:25
                  RE: Welcome to Open-DiscussionVishal Mittal2010-07-21 10:09
                        RE: Welcome to Open-Discussionrux pin2010-07-23 15:17
                              RE: Welcome to Open-DiscussionVishal Mittal2010-07-23 16:54

Post a followup to this message