CSV - Unquoted fields do not allow \r or \n (line 2)

后端 未结 8 1329
耶瑟儿~
耶瑟儿~ 2020-12-28 15:38

Trying to parse a CSV file, but still getting the error message Unquoted fields do not allow \\r or \\n (line 2)..

I found here at SO similar topic,

8条回答
  •  长发绾君心
    2020-12-28 16:13

    I realize this is an old post but I recently ran into a similar issue with a badly formatted CSV file that failed to parse with the standard Ruby CSV library.

    I tried the SmarterCSV gem which parsed the file in no time. It's an external library so it might not be the best solution for everyone but it beats parsing the file myself.

    opts = { col_sep: ';', file_encoding: 'iso-8859-1', skip_lines: 5 }
    SmarterCSV.process(file, opts).each do |row|
      p row[:someheader]
    end
    

提交回复
热议问题