Quote all fields in CSV output

前端 未结 2 395
北荒
北荒 2021-01-17 10:24
@out = File.open(\"#{File.expand_path(\"CSV\")}/#{file_name}.csv\", \"w\")
CSV::Writer.generate(@out) do |csv|
  csv << [\"01\", \"02\", \"test\"]
end
@out.clo         


        
2条回答
  •  庸人自扰
    2021-01-17 11:07

    So why not double quote them?

    @out = File.open("#{File.expand_path("CSV")}/#{file_name}.csv", "w")
    CSV::Writer.generate(@out) do |csv|
      csv << ['"01"', '"02"', '"test"']
    end
    @out.close
    

提交回复
热议问题