-
-
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
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