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
0
votes
1 answer

Rails 3.2 or 4.x way to submit a form/file for preview

I'm trying to create a form, where I can upload an CSV file to import or to preview before import it. In my form I have: <%= form_for(@contact_import, :remote => true) do |f| %> <% if @contact_import.errors.any? %>
Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
0
votes
0 answers

rails upload csv with FasterCSV to database IN UTF8

rails - 2.3.8 ruby - 1.8.7 I really searched old questions but found nothing. The deal is: Read from a .csv and update that info to my table in UTF8, but special chars like 'á','è','û' are changed for '?'. My table supports all this kind of chars.…
0
votes
3 answers

FasterCSV: columns into an array -- rails

I'm trying to get fastercsv setup so that rather than parsing each row, it will place each column into an multi array. CSV import file: id, first name, last name, age 1, joe, smith, 11 2, jane, doe, 14 Save to array named people: people[0][0] would…
Jeffrey
  • 4,098
  • 11
  • 42
  • 66
0
votes
0 answers

Why do I get "FasterCSV::MalformedCSVError: Illegal quoting error"?

I'm driving myself slight crazy with this one. I am trying to import a CSV file: uploaded_io = File.read("amazon_import.csv") FasterCSV.parse(uploaded_io, {:headers => true, :quote_char => '"', :col_sep => "\t"}).each do |row_data| new_record =…
Raoot
  • 1,751
  • 1
  • 25
  • 51
0
votes
2 answers

Problems with FasterCSV (Ruby)

I'm writing a program, that creates a csv-File. And I have a problem right at the beginning. So, my code is def create_csv destfile = Rails.root.join("public", "reports", "statistic_csv#{id}.csv") csv_string = FasterCSV.generate do…
jenia
  • 55
  • 6
0
votes
1 answer

Error with Paperclip / FasterCSV Processing for optional csv upload

I have a page where a user can import data to the site. either in the form of copy and pasting into a text area from excel, or by uploading a .csv file. The controller checks if a csv has been uploaded - if so it processes this, else it will process…
Chris
  • 648
  • 3
  • 9
  • 20
0
votes
1 answer

open and return fastercsv object with headers

I have a data sample like following Ticker,Date/Time,Conseqhigher,Conseqlower,H,L,newHigh,newLow,Prevbarlow,Prevbarhigh,uptrend,dntrend,min15low,min15high EUR.USD-IDEALPRO-CASH,2012-02-19…
junkone
  • 1,427
  • 1
  • 20
  • 45
0
votes
2 answers

RoR ActiveRecord find_by_sql Question

I want to preface this question by stating that I am fairly new to Ruby development, however, personally, I've dedicated myself to trying to find the answers myself, as opposed to whimsically asking questions on forums. That being said, this is my…
Rb.Ridge
  • 3
  • 2
0
votes
1 answer

What is the Ruby on Rails-way to import a structured comma delimited file and then create records Activerecord

I have a structured comma delimited file that has two record types. The different records are differentiated by a header entry: H or P. The file format follows: "H","USA","MD","20904" "P","1","A","Female","W" "P","2","A","Male","H" I'd like to…
Mutuelinvestor
  • 3,384
  • 10
  • 44
  • 75
0
votes
3 answers

Ruby csv import get code smaller but equal

I'm new to rails and ruby... How can i refactor such code, which import's from csv file data? Now i have such code if row[qnt].to_s != "" eqnt = /(\d+)/.match(row[qnt])[0].to_s else eqnt = 0 end I try something like if…
Valdis Azamaris
  • 1,433
  • 5
  • 22
  • 47
0
votes
2 answers

Using Ruby to replace specific records in a CSV file with records from another CSV file

I have two large-ish CSV files. One file is just a list of records. The other file is a list of records, but the first column is the line number of the record that it modifies in the other file. It doesn't replace the whole row; It just replaces the…
Jeremy Baker
  • 3,986
  • 3
  • 24
  • 27
0
votes
2 answers

FasterCSV - raising MalformedCSVError when it shouldn't

Sample…
Kyle
  • 1,054
  • 2
  • 14
  • 27
0
votes
1 answer

Ruby CSV read strings and numbers from MySQL exported csv

I exported tables and queries from SQL. The ruby (1.9+) way to read csv appears to be: require 'csv' CSV.foreach("exported_mysql_table.csv", {:headers=>true}) do |row| puts row end Which works great if your data is like…
xxjjnn
  • 14,591
  • 19
  • 61
  • 94
0
votes
1 answer

FasterCSV default options and their usage

FasterCSV has a default options hash; DEFAULT_OPTIONS = { :col_sep => ",", :row_sep => :auto, :quote_char => '"', :converters => nil, :unconverted_fields => nil, …
Kibet Yegon
  • 2,763
  • 2
  • 25
  • 32
0
votes
1 answer

Swapping columns in FasterCSV::Table

I have almost 1000+ CSV files where I need to shuffle several columns and recreate each CSV file with the shuffled columns. As an example, initial CSV file has "H1", "H2" and "H3" columns. The new CSV file will have columns "H1", "H3" and…
kishore
  • 541
  • 1
  • 6
  • 18
1 2 3
10
11