Skip to content

Instantly share code, notes, and snippets.

@stve
Created May 20, 2010 14:11
Show Gist options
  • Select an option

  • Save stve/407590 to your computer and use it in GitHub Desktop.

Select an option

Save stve/407590 to your computer and use it in GitHub Desktop.
Convert an xlsx file to a csv
#!/usr/bin/env ruby
require 'rubygems'
require 'fastercsv'
require 'roo'
if ARGV.size >= 1
file = ARGV.first
if file && File.exists?(file) && File.extname(file) == '.xlsx'
basename = File.basename(file, '.xlsx')
puts "Converting #{basename} to csv"
excel_file = Excelx.new(file)
dir = File.dirname(File.expand_path(file))
csv_filename = File.join(dir, "#{basename}.csv")
puts "Saving #{basename} to #{csv_filename}"
excel_file.to_csv(csv_filename)
end
else
puts "No file specified"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment