2

Goal for my code is to process all the .xls files in a directory and convert them all to .csv. This has worked in the past but after updating Ruby and Roo it is showing the error below. I am using Ruby 1.9.3-p362 and Roo 1.11.2.

require 'rubygems'
require 'csv'
require 'iconv'
require 'mysql2'
require 'mysql'
require 'roo'

begin
    Dir["#{@work_path}/*.xls"].each do |file|  
        begin
          file_path = "#{file}"
          file_basename = File.basename(file, ".xls")
          xls = Excel.new(file_path)
          xls.to_csv("#{@kenshoo_work_path}#{file_basename}.csv")
          @log.info("Converted file #{file}")
          FileUtils.remove(file)
          @log.info("Deleted file #{file}")
        rescue Exception => e
          @log.warn("Unable to convert file: #{file_basename} into csv because #{e.message}")
        end
    end
end

For every file I get the following error message:

Unable to convert file: #{file} into csv because uninitialized constant Excel

Any help is appreciated. Thanks.

madth3
  • 7,275
  • 12
  • 50
  • 74
analyticsPierce
  • 2,979
  • 9
  • 57
  • 81

1 Answers1

4

roo has Excel class within the Roo:: namespace. You need to replace all instances of Excel with Roo::Excel

The older versions did not namespace classes under Roo::, so that would explain why your code broke after update.

The new repository is here: https://github.com/Empact/roo

Dogbert
  • 212,659
  • 41
  • 396
  • 397