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

前端 未结 7 1661
别跟我提以往
别跟我提以往 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:48

    You can supply source encoding straight in the file mode parameter:

    CSV.foreach( "file.csv", "r:windows-1250" ) do |row|
       <your code>
    end
    
    0 讨论(0)
提交回复
热议问题