Ruby: cannot parse Excel file exported as CSV in OS X

前端 未结 6 1107
旧时难觅i
旧时难觅i 2021-02-03 10:52

I\'m using Ruby\'s CSV library to parse some CSV. I have a seemingly well-formed CSV file that I created by exporting an Excel file as CSV.

However CSV.open(filen

6条回答
  •  滥情空心
    2021-02-03 11:14

    I had similar problem. I got an error:

    "error_message"=>"Illegal quoting in line 1.", "error_class"=>"CSV::MalformedCSVError"
    

    The problem was the file had Windows line endings, which are of course other than Unix. What helped me was defining row_sep: "\r\n":

    CSV.open(path, 'w', headers: :first_row, col_sep: ';', quote_char: '"', row_sep: "\r\n") 
    

提交回复
热议问题