我推一些字符串到CSV文件:生成CSV文件時避免雙引號混淆?
csv_string = CSV.generate({col_sep: ";", row_sep: "\n"}) do |csv|
csv << ["101-41", "Sparri, \"Violet\" (rod) (1 bunt á 10 stk.)"]
end
當CSV文件最終生成一個常規Excel安裝顯然會正確顯示的內容,而是通過純文本編輯器仔細一看(如Sublime文本)顯示雙引號引起混淆:
10-41;"Sparri, ""Violet"" (rod) (1 bunt á 10 stk.)"
我該如何避免這種情況?在推送到CSV文件之前,我應該將雙引號轉換爲不同的內容嗎?
狀態OK,所以我應該乾脆把它保留原樣? – ChristofferJoergensen 2015-02-23 08:17:09
@ChristofferJoergensen是的,我會保持原樣。使用不同的'quote_char'可能會導致Excel出現問題。 – Stefan 2015-02-23 08:34:05
的確如此。 +1 – 2015-02-23 08:41:43