Skip to content

Instantly share code, notes, and snippets.

@bradleybuda
Created February 25, 2010 01:35
Show Gist options
  • Save bradleybuda/314112 to your computer and use it in GitHub Desktop.
Save bradleybuda/314112 to your computer and use it in GitHub Desktop.
Extract CSVs from an XLSX file with roo
require 'rubygems'
# wow that's a lot of unnecessary dependencies
%w(builder nokogiri rubyzip google-spreadsheet-ruby spreadsheet roo).each { |g| gem g }
require 'roo'
in_file = ARGV.shift
spreadsheet = Excelx.new(in_file)
spreadsheet.sheets.each_with_index do |sheet_name, i|
spreadsheet.default_sheet = sheet_name
out_file = File.expand_path("./#{File.basename(in_file)}_#{sheet_name}.csv")
spreadsheet.to_csv(out_file)
puts "Wrote sheet #{i + 1} to #{out_file}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment