@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”,“test”
答案 0 :(得分:20)
更改
CSV::Writer.generate(@out)do |csv|
到
CSV::Writer.generate(@out, {:force_quotes=>true}) do |csv|
答案 1 :(得分:-3)
那么为什么不加倍引用呢?
@out = File.open("#{File.expand_path("CSV")}/#{file_name}.csv", "w")
CSV::Writer.generate(@out) do |csv|
csv << ['"01"', '"02"', '"test"']
end
@out.close