Created
January 4, 2017 18:15
-
-
Save callumj/7f9aca229f1df01a94a40e1195293018 to your computer and use it in GitHub Desktop.
Collate multiple CSV into sheets in one Excel workbook using RubyXL
This file contains hidden or 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
files = Dir.glob("#{ENV["FOLDER"]}/**.csv").sort | |
files.each do |file| | |
worksheet = workbook.add_worksheet(file.gsub("#{ENV["FOLDER"]}/", "").gsub(".csv", "").gsub("*", "")) | |
row_indx = 0 | |
CSV.foreach(file) do |row| | |
row.each_with_index do |cell, cell_indx| | |
worksheet.add_cell(row_indx, cell_indx, cell) | |
end | |
row_indx += 1 | |
end | |
end | |
workbook.write("#{ENV["FOLDER"]}/collated.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment