Skip to content

Instantly share code, notes, and snippets.

@gotwalt
Created February 23, 2011 09:45
Show Gist options
  • Save gotwalt/840226 to your computer and use it in GitHub Desktop.
Save gotwalt/840226 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