Did you find a great spreadsheet you would like to use to seed your database? Or maybe your client has given you an excel sheet of information that you need to seed the database with for their webpage? I’m sure you don’t really want to, nor have the time to copy and paste all of the information into your seed file. This would take precious time away from building out a beautiful application with a bunch of great functionality! Well, you’re in luck, because today I am going to give you a step by step guide to convert your spreadsheet to a CSV file to seed your database with.

Please keep in mind, the steps regarding a spreadsheet will be based off a spreadsheet created using Numbers on a Macbook. Windows may differ in a few keys, but the steps should generally be the same.

Cleaning Up Your Spreadsheet

Image for post

Each row in your spreadsheet will account for an instance, while each column will be a value within this instance. If your spreadsheet has headers, the header of the column will be the key of the key value pair within this instance. That being said, this guid will assume, your spreadsheet has headers.

Please be sure the spreadsheet is set up with the first row being your headers and every row after that being your values that you would like to convert into an instance, of course matching each column in the row with it’s matching header.

You do not want any additional rows outside of this because it will ruin the set up of information being seeded and could cause null values within your seeded database. A title on your spreadsheet is okay, as long as it does not account for any cells. Your column headers must start on row 1 and your columns must begin at column A.

#csv-import #database #ruby-on-rails #ruby #csv

Seeding Your Rails Database With A Spreadsheet
2.35 GEEK