@out = File.open("#{File.expand_path("CSV")}/#{file_name}.csv","w") CSV::Writer.generate(@out) do |csv| csv << ["01","02","test"] end @out.close
当我运行上面的代码,它将CSV中的值存储为
01,02.测试
我想要他们存储为
“01”,“02”,“测试”
解决方法
更改
CSV::Writer.generate(@out)do |csv|
至
CSV::Writer.generate(@out,{:force_quotes=>true}) do |csv|