# Import excel / csv files

**URL:** <https://www.ruby-forum.com/t/import-excel-csv-files/175891>\
**Category:** Rails\
**Created:** [September 22, 2009, 10:10am UTC](https://www.ruby-forum.com/t/import-excel-csv-files/175891 "2009-09-22T10:10:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![andkjaer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@andkjaer](https://www.ruby-forum.com/u/andkjaer)\
**Post date:** [September 22, 2009, 10:10am UTC](https://www.ruby-forum.com/t/import-excel-csv-files/175891/1 "2009-09-22T10:10:29Z")

</div>

Hey,  
What way is the best to do imports of CSV files?

---

<div class="post-metadata">

**Author:** ![andkjaer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@andkjaer](https://www.ruby-forum.com/u/andkjaer)\
**Post date:** [September 22, 2009, 10:10am UTC](https://www.ruby-forum.com/t/import-excel-csv-files/175891/2 "2009-09-22T10:10:29Z")

</div>

If you mean CSV to DB records, you should use fixtures.

On terminal window.  
rake db:fixtures:load FIXTURES=table\_name RAILS\_ENV=development

Change ‘table\_name’ and RAILS\_ENV=~ as you like.  
This will import CSV as DB records.

---

<div class="post-metadata">

**Author:** ![andkjaer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@andkjaer](https://www.ruby-forum.com/u/andkjaer)\
**Post date:** [September 22, 2009, 12:31pm UTC](https://www.ruby-forum.com/t/import-excel-csv-files/175891/3 "2009-09-22T12:31:44Z")

</div>

Goro Kuroita wrote:

> If you mean CSV to DB records, you should use fixtures.
> 
> On terminal window.  
> rake db:fixtures:load FIXTURES=table\_name RAILS\_ENV=development
> 
> Change ‘table\_name’ and RAILS\_ENV=~ as you like.  
> This will import CSV as DB records.

Can you exapnd on this idea, I needed to bring in a whole load of  
records to my app from a CSV and wrote a custom method (with fasterCSV)  
to read them in. Am now wondering if fixtures would have been a better  
way to go and maybe I should be using them in future as I import more  
data to my app?

---

<div class="post-metadata">

**Author:** ![andkjaer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@andkjaer](https://www.ruby-forum.com/u/andkjaer)\
**Post date:** [September 23, 2009, 1:24am UTC](https://www.ruby-forum.com/t/import-excel-csv-files/175891/4 "2009-09-23T01:24:57Z")

</div>

Thank’s Masuda, but what im looking for is a solution where the user  
can upload a CSV file an update the DB records that way.

---

<div class="post-metadata">

**Author:** ![andkjaer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@andkjaer](https://www.ruby-forum.com/u/andkjaer)\
**Post date:** [September 22, 2009, 4:22pm UTC](https://www.ruby-forum.com/t/import-excel-csv-files/175891/5 "2009-09-22T16:22:14Z")

</div>

Goro Kuroita wrote:

> If you mean CSV to DB records, you should use fixtures.
> 
> On terminal window.  
> rake db:fixtures:load FIXTURES=table\_name RAILS\_ENV=development
> 
> Change ‘table\_name’ and RAILS\_ENV=~ as you like.  
> This will import CSV as DB records.

Poppycock. Fixtures are so broken that they’re worth avoiding  
completely (I wish they’d be removed from Rails). For prepopulating the  
DB, use the DB’s native CSV import or something like seed\_fu. For  
dynamic CSV import in the application, fastercsv might be useful.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![andkjaer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@andkjaer](https://www.ruby-forum.com/u/andkjaer)\
**Post date:** [September 23, 2009, 3:21pm UTC](https://www.ruby-forum.com/t/import-excel-csv-files/175891/6 "2009-09-23T15:21:27Z")

</div>

Milan D. wrote:

> Why do you say that fixtures are broken?

The short answer is that they’re unsuited to their intended purpose  
(populating the test DB). They’re better than nothing, but are an  
inferior alternative to other solutions now available. I’ll get into  
the long answer if you really want, or just search the list archives.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![andkjaer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@andkjaer](https://www.ruby-forum.com/u/andkjaer)\
**Post date:** [September 23, 2009, 3:16pm UTC](https://www.ruby-forum.com/t/import-excel-csv-files/175891/7 "2009-09-23T15:16:26Z")

</div>

Why do you say that fixtures are broken?

On Sep 22, 4:22 pm, Marnen Laibow-Koser \<rails-mailing-l…@andreas-
