Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7923593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:22:35+00:00 2026-06-03T17:22:35+00:00

I have data from an Excel spreadsheet that I want to import into a

  • 0

I have data from an Excel spreadsheet that I want to import into a database via Rails. I am using Rails 3.2.3 and Ruby 1.9.2.

The data is usernames and passwords, file name is member.xlsx.

<%= form_for @member do |f| %>
    <%= f.text_field :import,
        :maxlength=>'50',
        :style=>'width: 250px;',
        :placeholder => 'browse file *.sql or *.xlsx' %>
    <%= f.submit  %><% end %>

My table:

create_table :members do |t|
  t.string :username
  t.string :password_hash
  t.string :password_salt

Solved

Solution

I’m using the spreadsheet gem for parse the Excel file and the CarrierWave gem for uploading the Excel file. Because I’m using devise model for user, here’s what the controller for importing the file looks like

def import
    if params[:excel_file].nil?
      redirect_to user_new_import_path, :flash => { :error => 'You have not selected a file'}
    else
      test_file = params[:excel_file]
      file = ExcelUploader.new
      file.store!(test_file)
      book = Spreadsheet.open "#{file.store_path}"
      sheet1 = book.worksheet 0
      sheet1.each 1 do |row|
        name = row[0]
        email = row[2]
        generated_password = Devise.friendly_token.first(6) 
        temp_password = generated_password
        @user = User.create(:name => name, :email => email, :password => temp_password, :password_confirmation => temp_password)     
         UserMailer.password_send(@user).deliver
      end
      if @user.save
        redirect_to users_path, :notice => "success"
      else
        redirect_to new_import_user_path, :flash => { :error => 'error. try again' }
      end
    end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:22:36+00:00Added an answer on June 3, 2026 at 5:22 pm

    Importing a sql file is a horrible idea since the sql could do anything to your db.

    Importing an Excel file works ok. There are Excel gems to read the data. The roo gem is available for the xlsx format but I haven’t tested it. I tell users to use Excel to store the file in xls format and then they upload that.

    Even better (from the app developer’s point of view) is to import csv files. Downside of csv is that the file only contains exactly one table.

    On the other hand, a problem with Excel import is that people can supply you with multiple tab files, with formulas rather than values in the cells, etc. — So be sure to include plenty of error checking.

    Frequent problems: people entering dates as strings in the Excel sheet when your code expects Date objects. Or numbers entered by people as strings. Your code should test and handle these issues.

    See http://rubygems.org/gems/roo

    Re: “give me some code” — That’s not how StackOverflow works. Hopefully the above will assist you on your journey.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel spreadsheet that needs to display data from our SQL database.
I have an Excel file that gets external data from database table. I need
i have existing code that generates a spreadsheet from excel using OpenXML. It works
I am importing massive amounts of data from Excel that have various table layouts.
I have some data from JQGrid that should be exported to excel. So, we
I have few text and excel file, from which I need to import data
we have a C++ Win32 DLL that reads data from Excel. The application uses
I need to import tabular data into my database. The data is supplied via
I wrote an ASP.NET page that imported data from an Excel spreadsheet without any
i am trying to insert data from excel sheet into database in java. for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.