Questions tagged [fastercsv]

Popular Ruby library/gem for working with CSV format files.

FasterCSV is a very popular Ruby gem for workin with CSV (comma-separated values) format files and data. It can import, export, and perform various other operations on data in CSV format.

164 questions
3
votes
1 answer

Having issues importing a CSV File using FasterCSV

I am new to Rails and I have figured out how to export results from my Database but I am having issues creating new records from a CSV File. With the code listed below I want to be able to import a CSV file and fill in the last two columns with…
Kyle
  • 155
  • 3
  • 11
3
votes
5 answers

FasterCSV: Read Remote CSV Files

I can't seem to get this to work. I want to pull a CSV file from a different webserver to read in my application. This is how I'd like to call it: url = 'http://www.testing.com/test.csv' records = FasterCSV.read(url, :headers => true,…
neezer
  • 19,720
  • 33
  • 121
  • 220
3
votes
5 answers

Heroku file upload problem

I've been having a problem uploading a CSV file to Heroku and processing it. It works fine in my local environment. Just do be clear, I don't need to save the file on Heroku, just access it during the request in order to convert it into a string for…
Avishai
  • 4,512
  • 4
  • 41
  • 67
3
votes
2 answers

Huge text or excel data Import FASTER into sql

I have a huge text file that has 1 million rows and each row there is only 28 length number as text. I want to import them into sql server that has table corresponding column. So that a million data will be inserted to one column DB table. I used…
Arno
  • 304
  • 1
  • 3
  • 11
3
votes
1 answer

Rails - number of rows in a file

Hey. How can I get a total number of rows in a file (do not want to do it with loop). I'm reading CSV file. Example 1 CSV.open('clients.csv', 'r') Example 2 FasterCSV.foreach('clients.csv') Thx.
xpepermint
  • 35,055
  • 30
  • 109
  • 163
3
votes
3 answers

Exporting to CSV from complex rails query

I was following this railscast video but I'm having serious difficulties to export my data to excel (or CSV for this matter). I'm using will_paginate in some data that I show on frontend like this: sql = "select complex..." @data =…
tostasqb
  • 717
  • 1
  • 12
  • 28
3
votes
2 answers

No such file or directory error when loading csv file in Rails

I'm trying to load data from a csv file to my rails database. this is my rake task: namespace :db do require 'csv' desc "load user data from csv" task :load_csv_data => :environment do CSV.foreach("transfers.csv") do |row| …
Uri Klar
  • 3,800
  • 3
  • 37
  • 75
3
votes
3 answers

Ruby CSV, using square brackets as row separators

I'm trying to use square brackets '[]' as a row separator in a CSV file. I must use this exact format for this project (output needs to match LEDES98 law invoicing format exactly). I'm trying to do this: CSV.open('output.txt', 'w', col_sep: '|',…
Dan
  • 641
  • 9
  • 25
3
votes
2 answers

This code is able to read a CSV file from file system but what about reading from a URL?

I wrote this rake task that enables me to read a csv file from a file on the local filesystem of my app, but how do I tweak this to make it read a file from a url? desc "This class will read a csv file and display its contents on the screen" task…
banditKing
  • 9,405
  • 28
  • 100
  • 157
3
votes
2 answers

Memory issue with huge CSV Export in Rails

I'm trying to export a large amount of data from a database to a csv file but it is taking a very long time and fear I'll have major memory issues. Does anyone know of any better way to export a CSV without the memory build up? If so, can you show…
user1402671
2
votes
1 answer

Ruby CSV.parse very picky when encountering quotes

I am finding the CSV parsing in Ruby 1.9.3 to be remarkably fragile. So much so that I am wondering if I am doing something wrong If I do the following in irb I get an error: 1.9.3-p125 :011 > require 'csv' => true 1.9.3-p125 :012 > a =…
Dave Isaacs
  • 4,499
  • 6
  • 31
  • 44
2
votes
1 answer

Faster CSV + trying to find unique items

I have a csv file where I'm trying to find all the uniq values in columns past column 2 where column 1 has the same value and consolidate that in a new csv file. I know, that sounds way confusing so here's an example: a sample of the original file…
MarkL
  • 147
  • 2
  • 8
2
votes
3 answers

merge CSV files on a common field with ruby/fastercsv

I have a 'master' file with a number of columns: 1 2 3 4 5. I have a few other files, with fewer rows than the master file, each with columns: 1 6. I'd like to merge these files matching on the column 1 field and add column 6 to the master. I've…
chuckfinley
  • 763
  • 11
  • 26
2
votes
4 answers

FasterCSV tutorial to import data to database?

Is anyone aware of any tutorials that demonstrate how to import data in a Ruby app with FasterCSV and saving it to a SQLite or MySQL database? Here are the specific steps involved: Reading a file line by line (the .foreach method does this…
Jim Connors
  • 297
  • 4
  • 14
2
votes
3 answers

Problems trying to parse CSV file with umlaut's etc in it using Ruby 1.8 / FasterCSV

I have a CSV file with lines like this in it: ...,"Städtische Galerie im Lenbachhaus",... I am using Ruby 1.8, with the FasterCSV gem, like so: FasterCSV.foreach(file, :encoding => 'u', :headers => :first_row) do |r| as =…
Chris Kimpton
  • 5,546
  • 6
  • 45
  • 72
1 2
3
10 11