19
16

More than 5 years have passed since last update.

Excelで文字化けしないCSV(UTF-8)を書き出す方法

Posted at

文字化けを回避するにはファイルの先頭にBOMを明示的に出力しないといけない。

# encoding: utf-8
File.open("sample.csv", 'w') do |f|
  f.print "\xEF\xBB\xBF" # BOM
  f.puts "UTF-8,の文字コード,のCSV,文字列"
end

Mac版Excelについては下記が参考になる。
http://qiita.com/items/88879711245a420f713d

19
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
16