Created
February 23, 2011 09:45
-
-
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
This file contains 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
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