Module: ExcelImport::ImportFile

Defined in:
lib/excel-import.rb

Defined Under Namespace

Classes: FormatError

Class Method Summary collapse

Class Method Details

.open_spreadsheet(file) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/excel-import.rb', line 74

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