I am generating CSV files that needs to be opened and reviewed in Excel once they have been generated. It seems that Excel requires a different encoding than UTF-8.
Here is my config and generation code:
csv_config = {col_sep: ";",
row_sep: "\n",
encoding: Encoding::UTF_8
}
csv_string = CSV.generate(csv_config) do |csv|
csv << ["Text a", "Text b", "Text æ", "Text ø", "Text å"]
end
When opening this in Excel, the special characters are not being displayed properly:
Text a Text b Text æ Text ø Text å
Any idea how to ensure proper encoding?
# encoding: UTF-8
as your Ruby file's first line (second if you have a hash-bang line,#!/usr/bin/env ruby
). I believe you are writing in UTF-8, but the Ruby source file is taken to be encoded as US_ASCII. (With Ruby 2.0+, source encoding defaults to UTF-8) – Touristyruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
so I suppose that means that my installation is already defaulting to UTF-8. – Jawbreaker