First off, a quick note on $KCODE - the values it takes are a little weird. 'utf8' is not valid; you're looking for one of these:
None (n or N) EUC (e or E) Shift_JIS (s or S) UTF-8 (u or U) (taken from http://blog.grayproductions.net/articles/bytes_and_characters_in_ruby_18 ) You can also pass an :encoding option (same choice of values) to FasterCSV. I'd also make sure that the file is really UTF8, as many CSVs produced by Excel will instead be in ISO8859-1 (technically, an incompatible MS variant of that standard [CP1252]). You may have to crunch the data somewhat to get it to behave, as the MS Office products are also notorious for stuffing "smart quotes" and other non-standard characters into files... --Matt Jones On Jun 17, 6:51 pm, Hu Ma <rails-mailing-l...@andreas-s.net> wrote: > Hello all, > I'm trying to import some csv data (that has latin characters) using > faster csv but I keep getting a MalformedCSVError: > "Unclosed quoted field on line 1." > "/ruby/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/faster_csv.rb:1592:in > `shift'" > > I've tested the same code outside of the Rails application an it works > fine. > Can anyone help me? > > Here is the code: > > csv_options = { > :headers => false, > :return_headers => false, > :skip_blanks => false > > } > > csv_file_name = File.dirname(__FILE__) + "/../../Files.TXT" > data = "" > FasterCSV.foreach(csv_file_name, csv_options) do |row| > data << row.to_s + "<br>" > end > > And the first two lines in the file: > "20.1","Maria José",,"9" > "10.2","José Maria",,"10" > > I'm using fastercsv 1.2.3 and rails 2.1.2 > > Note: I've tried adding $KCODE = "utf8" but it still does not work. > > Thanks. > Best regards, > Migrate > -- > Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---