ArgumentError: Incorrect number of arguments (3 for 1..2) when importing .xlsx extension

I have a problem importing an excel file where the is.xls extension works fine but when the extension is .xlsx it gives argument errors.

def open_spreadsheet(file)

  case File.extname(file.original_filename)
    when ".csv" then Roo::Csv.new(file.path, nil, :ignore)
    when ".xls" then Roo::Excel.new(file.path, packed: nil, file_warning: :ignore)
    when ".xlsx" then Roo::Excelx.new(file.path, nil, :ignore)
    else raise "Unknown file type: #{file.original_filename}"
  end
end

      

+3


source to share


3 answers


Try



 Roo::Excel.new(file.path, packed: false, file_warning: :ignore)

      

+3


source


If you look at the documentation, Roo :: Excelx.new (the initialize method) only takes two arguments.

http://www.rubydoc.info/gems/roo/Roo/Excelx



Change line 6 to:

when ".xlsx" then Roo::Excelx.new(file.path, :ignore)

      

+1


source


I solved my problem by doing some changes in this case

 when ".xlsx" then Roo::Excelx.new(file.path, packed: nil, file_warning: :ignore)

      

0


source







All Articles