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
5
votes
4 answers

Speed up csv import

I want to import big amount of cvs data (not directly to AR, but after some fetches), and my code is very slow. def csv_import require 'csv' file = File.open("/#{Rails.public_path}/uploads/shate.csv") csv = CSV.open(file,…
byCoder
  • 3,462
  • 6
  • 28
  • 49
4
votes
3 answers

Ruby on Rails Import CSV into MySQL

Newbie question.... Trying to start a project in rails. I have different spreadsheets in csv format I'd like to import into the MySQL database to be able to manipulate the data. After looking around on stackoverflow, Google, etc. I wrote a rake task…
DaveG
  • 1,203
  • 1
  • 25
  • 45
4
votes
2 answers

Generating fields containing newline with Ruby CSV::Writer

I want to make CSV::Writer generate a line break within a quoted string: A,B,"Line Line",C So that the row would display in Excel as: A,B,Line,C Line Is it possible to prevent CSV:Writer from stripping out newlines? If not, would switching to…
Ray Myers
  • 533
  • 5
  • 14
4
votes
3 answers

FasterCSV: several separators

My Rails3 app parses user-uploaded CSV files. As can be expected, users upload tab-separated AND comma-separated files. I want to support both. My code: input = CSV.read(uploaded_io.tempfile, { encoding: "UTF-8", :col_sep => "\t"}) QUESTION:How to…
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
4
votes
3 answers

How can I further process the line of data that causes the Ruby FasterCSV library to throw a MalformedCSVError?

The incoming data file(s) contain malformed CSV data such as non-escaped quotes, as well as (valid) CSV data such as fields containing new lines. If a CSV format error is detected I would like to use an alternative routine on that data. With the…
s01ipsist
  • 3,022
  • 2
  • 32
  • 36
4
votes
2 answers

Rails3 CSV putting "" instead of actual quotes

Similar to this question except I don't use html_safe anywhere in the whole project. I generate a CSV file in index.csv.erb like this: <%= response.content_type = 'application/octet-stream' CSV.generate do |csv| @persons.each do |person| csv…
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
4
votes
1 answer

rails 3 ruby 1.9.2 CSV "already initialized constant .." warning

I want to add the ability to read/write data to a CSV file to one of my models. In versions of ruby prior to 1.9 this would have been done with fasterCSV, but this is now part of ruby. I have the following setup: #in my_model.rb require 'CSV' class…
Tom Close
  • 620
  • 5
  • 12
4
votes
2 answers

Converting uneven rows to columns with FasterCSV

I have a CSV data file with rows that may have lots of columns 500+ and some with a lot less. I need to transpose it so that each row becomes a column in the output file. The problem is that the rows in the original file may not all have the same…
srboisvert
  • 12,679
  • 15
  • 63
  • 87
4
votes
2 answers

How to import CSV files in rails?

I am making an application in which it import a csv file names user.csv.But the problem i am facing is that it gives an error ArgumentError in CsvimportController#import wrong number of arguments (1 for 0) And the code of the CsvimportController…
Mohd Anas
  • 634
  • 1
  • 9
  • 22
4
votes
2 answers

fasterCSV for ruby 1.9.3?

I'm trying to export my report in a CSV format document. For that i used fasterCSV but,i faced Please switch to Ruby 1.9's standard CSV library. It's FasterCSV plus support for Ruby 1.9's m17n encoding engine. error. Can any one help me to solve…
Ferdy
  • 666
  • 7
  • 25
3
votes
3 answers

How do you change headers in a CSV File with FasterCSV then save the new headers?

I'm having trouble understanding the :header_converters and :converters in FasterCSV. Basically, all I want to do is change column headers to their appropriate column names. something like: FasterCSV.foreach(csv_file, {:headers => true,…
btelles
  • 5,390
  • 7
  • 46
  • 78
3
votes
1 answer

Error parsing CSV with FasterCSV gem (MalformedCSVError)

FasterCSV is raising MalformedCSVError (Illegal Quoting) in this line: |0150|1161623|Medicamentos e genericos "EPP".|1423|PB| This is the code: FasterCSV.foreach(path_to_file, :col_sep => '|') do |row| ... end Any ideas? tks!!
Josué Lima
  • 483
  • 6
  • 18
3
votes
1 answer

How to prevent Rails from encoding entities in FasterCSV output

I'm using FasterCSV to produce CSV output of my reports in a Rails 3 application. Here's a code snippet: <%= FasterCSV.generate do |csv| @groups.each do |b| record = [ b.group, b.organization_name, b.status, b.comments ] csv << record …
Rafe
  • 3,056
  • 1
  • 22
  • 25
3
votes
3 answers

FasterCSV: Check whether a file is invalid before accepting it - is there a simpler way?

I'm using FasterCSV on a Ruby on Rails application and currently it throws an Exception if the file is invalid. I've looked over the FasterCSV doc, and it seems that if I use FasterCSV::parse with a block, it'll read the file one line at a time,…
kikito
  • 51,734
  • 32
  • 149
  • 189
3
votes
1 answer

Using Ruby's fastercsv with character encodings

Using Ruby 1.8.7, I want to accept csv's into my system, even though this is an admin application, it seems I can get several different types of csvs. On my mac if I export from excel using "windows csv" option then fastercsv can read it out by…
Joelio
  • 4,621
  • 6
  • 44
  • 80
1
2
3
10 11