Ruby/Rails CSV parsing, invalid byte sequence in UTF-8

前端 未结 7 1730
别跟我提以往
别跟我提以往 2020-12-24 01:02

I am trying to parse a CSV file generated from an Excel spreadsheet.

Here is my code

require \'csv\'
file = File.open(\"input_file\")
csv = CSV.parse         


        
7条回答
  •  情歌与酒
    2020-12-24 01:38

    If you have only one (or few) file, so when its not needed to automatically declare encoding on whatever file you get from input, and you have the contents of this file visible in plaintext (txt, csv etc) separated with i.e. semicolon, you can create new file with .csv extension manually, and paste the contents of your file there, then parse the contents like usual.

    Keep in mind, that this is a workaround, but in need of parsing in linux only one big excel file, converted to some flavour of csv, it spares time on experimenting with all those fancy encodings

提交回复
热议问题