# Newbie wants to know..FasterCSV or just CSV?

**URL:** <https://www.ruby-forum.com/t/newbie-wants-to-know-fastercsv-or-just-csv/60759>\
**Category:** Rails\
**Created:** [May 17, 2006, 8:54am UTC](https://www.ruby-forum.com/t/newbie-wants-to-know-fastercsv-or-just-csv/60759 "2006-05-17T08:54:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [May 17, 2006, 8:54am UTC](https://www.ruby-forum.com/t/newbie-wants-to-know-fastercsv-or-just-csv/60759/1 "2006-05-17T08:54:00Z")

</div>

I’m trying to grab a CSV file from a user and let them upload it  
directly to my database, but doing some minor checks on the data before  
saving. Which is the easier way to implement this? CSV or FasterCSV? I  
saw that perhaps there were some issues with FasterCSV and csv files  
created from Mac versions of Excel.

Anyone have any experience with this and can recommend a newbie friendly  
path?

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [May 17, 2006, 9:46am UTC](https://www.ruby-forum.com/t/newbie-wants-to-know-fastercsv-or-just-csv/60759/2 "2006-05-17T09:46:47Z")

</div>

Hi Vince

to me FasterCSV is quite easy to understand and use (before picking up  
one  
of those two, I had a look at both APIs but found FasterCSV more  
intuitive).

Using excel CSV files exported on one platform (say PC) then imported on  
another (say Mac) will cause troubles (I had those problems just two  
days  
ago!). It seems that the exported data is not stored in UTF-8 but in  
ANSI,  
with platform-specific codepage.

hope this helps.

Thibaut

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [May 17, 2006, 10:51am UTC](https://www.ruby-forum.com/t/newbie-wants-to-know-fastercsv-or-just-csv/60759/3 "2006-05-17T10:51:22Z")

</div>

Thibaut BarrÃ¨re wrote:

> to me FasterCSV is quite easy to understand and use (before picking up  
> one  
> of those two, I had a look at both APIs but found FasterCSV more  
> intuitive).

It’s just that documentation is a little sparse on using it. Are there  
examples anywhere for having somebody upload a csv and then saving the  
contents to a database? I’m trying to parse just four fields: title,  
description, quantity, and price.

I saw a tip on rails.techno-weenie that uses migrations but couldn’t  
quite make sense of it.

> Using excel CSV files exported on one platform (say PC) then imported on  
> another (say Mac) will cause troubles

The clients could be anything (mac, win, linux) but the server is linux.  
Does that mean I’ll have problems unless the csv is also exported from a  
linux box? Is that an issue with the regular csv library too?

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [May 17, 2006, 1:10pm UTC](https://www.ruby-forum.com/t/newbie-wants-to-know-fastercsv-or-just-csv/60759/4 "2006-05-17T13:10:03Z")

</div>

> If you can wait 8pm UTC+2 I’ll post a sample of how to do that (I’m  
> working  
> on something similar).

I can definitely wait. Thanks very much!

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [May 17, 2006, 11:28am UTC](https://www.ruby-forum.com/t/newbie-wants-to-know-fastercsv-or-just-csv/60759/5 "2006-05-17T11:28:26Z")

</div>

> It’s just that documentation is a little sparse on using it. Are there  
> examples anywhere for having somebody upload a csv and then saving the  
> contents to a database? I’m trying to parse just four fields: title,  
> description, quantity, and price.

This library’s documentation doesn’t describe the file upload part of  
course.

I’d suggest you write a unit test to play with the parsing part first,  
using  
sample CSV data, then deal with the upload thingy once you’re done  
(‘step by  
step, ouuh baby’ like they sing it).

If you can wait 8pm UTC+2 I’ll post a sample of how to do that (I’m  
working  
on something similar).

The clients could be anything (mac, win, linux) but the server is linux.

> Does that mean I’ll have problems unless the csv is also exported from a  
> linux box? Is that an issue with the regular csv library too?

I think you’ll have the same issue with the regular csv. It’s more a  
behaviour of excel export and an issue with encoding and codepages than  
something caused by the library.

cheers

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [May 17, 2006, 7:55pm UTC](https://www.ruby-forum.com/t/newbie-wants-to-know-fastercsv-or-just-csv/60759/6 "2006-05-17T19:55:11Z")

</div>

I seem to recall that FasterCSV is GPL, while CSV is the same license as  
Ruby (MIT?). Repending on what you intend to do with your final  
product, licensing choices may matter to you.

vince wrote:

> I’m trying to grab a CSV file from a user and let them upload it  
> directly to my database, but doing some minor checks on the data before  
> saving. Which is the easier way to implement this? CSV or FasterCSV? I  
> saw that perhaps there were some issues with FasterCSV and csv files  
> created from Mac versions of Excel.
> 
> Anyone have any experience with this and can recommend a newbie friendly  
> path?

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [May 18, 2006, 12:21am UTC](https://www.ruby-forum.com/t/newbie-wants-to-know-fastercsv-or-just-csv/60759/7 "2006-05-18T00:21:20Z")

</div>

> I can definitely wait. Thanks very much!

Hi

here’s a sample of what I’m using - here if you don’t have headers  
defined  
on the first line of the csv:

```
FasterCSV.foreach(File.dirname( __FILE__ ) 

```

+“/…/fixtures/answers.csv”,  
:col\_sep =\> ‘;’,  
:headers =\> %w(id label question\_number next\_question\_number  
message))  
do |row|  
puts row[“label”]  
…  
end  
end

all the options are explained here : [http://fastercsv.rubyforge.org/](http://fastercsv.rubyforge.org/)

Asa: FasterCSV is “distributed under the user’s choice of the  
GPL[http://www.gnu.org/copyleft/gpl.html](http://www.gnu.org/copyleft/gpl.html)(see COPYING for details) or  
the Ruby  
software license [http://www.ruby-lang.org/en/LICENSE.txt](http://www.ruby-lang.org/en/LICENSE.txt) by James  
Edward  
Gray II.”, see [http://fastercsv.rubyforge.org/files/LICENSE.html](http://fastercsv.rubyforge.org/files/LICENSE.html) for  
details

cheers

Thibaut
