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

前端 未结 6 1102
旧时难觅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:25

    Try: CSV.open('filename', 'r', ?,, ?\r)

    As cantlin notes, for Ruby 2 it's:

    CSV.new('file.csv', 'r', :col_sep => ?,, :row_sep => ?\r)
    

    I'm pretty sure these will DTRT for you. You can also "fix" the file itself (in which case keep the old open) with the following vim command: :%s/\r/\r/g

    Yes, I know that command looks like a total no-op, but it will work.

提交回复
热议问题