Last active
August 10, 2022 19:19
-
-
Save aghuddleston/6c9fcf5d41c7f598fdeb to your computer and use it in GitHub Desktop.
Write a CSV file using Ruby 2.2.2 which can open in Excel, properly displaying accents.
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 'csv' | |
module DownloadService | |
OPEN_MODE = "w+:UTF-16LE:UTF-8" | |
BOM = "\xEF\xBB\xBF" #Byte Order Mark | |
def student_list | |
File.open("#{file_name}.tsv", OPEN_MODE) do |f| | |
csv_file = CSV.generate({:col_sep => "\t"}) do |csv| | |
# header row | |
csv << ['First_Name', 'Middle_Name', 'Last_Name'] | |
# put lots of rows in the csv file here | |
end | |
f.write BOM | |
f.write(csv_file) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This helped lot. Thank you @aghuddleston