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? -- Posted via http://www.ruby-forum.com/.
Thibaut Barrère
2006-May-17 07:45 UTC
[Rails] newbie wants to know..FasterCSV or just CSV?
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 -- [blog] http://www.dotnetguru2.org/tbarrere -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060517/4de70ec1/attachment.html
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 troublesThe 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.. -- Posted via http://www.ruby-forum.com/.
Thibaut Barrère
2006-May-17 09:26 UTC
[Rails] Re: newbie wants to know..FasterCSV or just CSV?
> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060517/33d22fe3/attachment.html
Vince W.
2006-May-17 11:10 UTC
[Rails] Re: Re: newbie wants to know..FasterCSV or just CSV?
> > 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! -- Posted via http://www.ruby-forum.com/.
Asa Hopkins
2006-May-17 17:55 UTC
[Rails] Re: newbie wants to know..FasterCSV or just CSV?
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?-- Posted via http://www.ruby-forum.com/.
Thibaut Barrère
2006-May-17 22:19 UTC
[Rails] Re: Re: newbie wants to know..FasterCSV or just CSV?
> > 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/ Asa: FasterCSV is "distributed under the user''s choice of the GPL<http://www.gnu.org/copyleft/gpl.html>(see COPYING for details) or the Ruby software license <http://www.ruby-lang.org/en/LICENSE.txt> by James Edward Gray II.", see http://fastercsv.rubyforge.org/files/LICENSE.html for details cheers Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060517/0335f149/attachment.html
Apparently Analagous Threads
- installing fastercsv into vendor directory
- How Can I insert another column data into the CSV file when I use FasterCSV?
- fastercsv, freezing into vendor/gems
- FasterCSV load file to table
- How do I use fastercsv to just read the header row and not the whole file?