Skip to content

Instantly share code, notes, and snippets.

@rorcraft
Created September 21, 2010 13:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rorcraft/589717 to your computer and use it in GitHub Desktop.
Save rorcraft/589717 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'roo'
pwd = File.dirname(__FILE__)
Dir.glob("#{pwd}/*.xls") do |file|
file_path = "#{pwd}/#{file}"
file_basename = File.basename(file, ".xls")
xls = Excel.new(file_path)
xls.to_csv("#{pwd}/#{file_basename}.csv")
end
@codepedia
Copy link

Hi Man thanks for this snippet of code. when I ran it I got the below error

rooxls2csv.rb:10:in block in <main>': uninitialized constant Excel (NameError) from rooxls2csv.rb:7:inglob'
from rooxls2csv.rb:7:in `

'

I fixed it by adding Roo::Excel...... check below.

!/usr/bin/env ruby

require 'rubygems'
require 'roo'

pwd = File.dirname(FILE)

Dir.glob("#{pwd}/*.xls") do |file|
file_path = "#{pwd}/#{file}"
file_basename = File.basename(file, ".xls")
xls =Roo::Excel.new(file_path)
xls.to_csv("#{pwd}/#{file_basename}.csv")
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment