Skip to content

Instantly share code, notes, and snippets.

@hungtrinh
Forked from gotwalt/shiftjis-csv.rb
Created November 18, 2015 07:03
Show Gist options
  • Save hungtrinh/00f2143db85c4532966e to your computer and use it in GitHub Desktop.
Save hungtrinh/00f2143db85c4532966e to your computer and use it in GitHub Desktop.
Convert a CSV file to Shift-JIS for use in Japanese versions of Microsoft Excel in ruby-1.8.7
require "iconv"
encoding = "SHIFT-JIS"
# Open a file for writing in the Shift-JIS format
File.open("output.csv", "w:#{encoding}") do |io|
# Read the CSV file, and convert CRs to CRLFs.
csv = File.open("input.csv").read.gsub("\r", "\r\n")
# Convert the CSV to the correct encoding
io.write Iconv.iconv(encoding, "UTF-8", csv).join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment