概要 BOM付きUTF-8のCSVファイルを出力してExcelで開けるようにする 詳細 BOM付きUTF-8のCSVファイルを出力してExcelで開けるようにします サンプル # encoding: utf-8 class File def self.insert_bom(input_filename, output_filename) src = File.read(input_filename) File.open(output_filename, "w:UTF-8") do |f| src = ' ' + src src.setbyte(0, 0xEF) src.setbyte(1, 0xBB) src.setbyte(2, 0xBF) f.print src end end end file = $*[0] exit unless File.exists? file File.in
![Ruby | BOM付きUTF-8のCSVファイルを出力してExcelで開けるようにする - Tbpgr Blog](https://cdn-ak-scissors.b.st-hatena.com/image/square/5c757bebce3d43236f9ad0a52cca0b0e4b660ee3/height=288;version=1;width=512/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Ft%2Ftbpg%2F20140204%2F20140204214012.png)