module ExcelImport::ImportFile

Public Class Methods

open_spreadsheet(file) click to toggle source
# File lib/excel-import.rb, line 73
def self.open_spreadsheet(file)
  extname = case file
  when ActionDispatch::Http::UploadedFile
    File.extname file.original_filename
  else
    File.extname file
  end

  case extname
    when '.sxc'
      Roo::Openoffice.new(file.path, nil, :ignore)
    when '.xls'
      Roo::Excel.new(file.path, nil, :ignore)
    when '.xlsx'
      Roo::Excelx.new(file.path, nil, :ignore)
    else
      raise FormatError.new "Unsupported file format #{extname}"
  end

end