Importing of excel data to MySQL database is more easier in Rails3 using roo gem.

Ruby_On_Rails_logoFollowing is a basic example to demonstrate how to get the data from an excel sheet and save to your database. Suppose you have an excel sheet named student_details.xls which contain the student details such as .Name.,”Phone.,.Address..We have to save them in our database but it will take a huge time if we insert them manually. Here we can user .roo. gem to fetch the data from excel sheet and save to database in a fly.

Roo gem allows us to access the contents of

* Open-office spreadsheets (.ods)

* Excel spreadsheets (.xls)

* Google (online) spreadsheets

* Excel.s new file format .xlsx

Step . 1

Add the gem in your gem file

Then run the command

It will install the roo gem for you.

Step . 2

Place your excel sheet in the rails application such as in public folder.

Step . 3

Now its time to change your controller like below.

Add the following line in your controller

Create a new method where you will fetch the data from excel sheet and save it in your database.

Now whenever you call this method in your view file roo gem will fetch the data accordingly and save to your database.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
The following two tabs change content below.

Srikanta Mohapatra

Sr. Software Eng.. at Andolasoft Inc.
Nearly 4.10 years of Experience In Ruby 1.8.7- 1.9.x, Rails 2.3.8 . 3.x, Mysql, Postgress,Asp.net,sqlserver with all development steps and analysis designing.Expertise to implement PayPal,E-commerce & Social Networking,RefineryCMS & BrowserCMS , PUBNUB,configuration tools like Git, SVN, Heroku, Search engine like Elastics & Solr Search.

Leave a Reply