Ruby: How to generate CSV files that has Excel-friendly encoding
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? The top voted answer from @joaofraga worked for me,