Forked from mrluanma/howto_put_utf8_bom_in_csv_file.rb
Created
March 21, 2017 02:24
-
-
Save anvyzhang/9408f53ec10d7e58a6f531b451b5525d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
$KCODE = 'u' | |
require 'csv' | |
File.open('tmp.csv', 'wb') do |csv_file| | |
# 输出标明文本编码为 UTF-8 的 BOM | |
csv_file.write("\xEF\xBB\xBF") | |
CSV::Writer.generate(csv_file) do |csv| | |
csv << %w{第一 第二 第三} | |
csv << (1..3).to_a | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment