ArgumentError: wrong number of arguments (3 for 1.

2019-05-09 23:19发布

I have a problem when import the excel file, when extension is.xls its working properly but when extension is .xlsx it give 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条回答
Evening l夕情丶
2楼-- · 2019-05-09 23:58

Try

 Roo::Excel.new(file.path, packed: false, file_warning: :ignore)
查看更多
对你真心纯属浪费
3楼-- · 2019-05-10 00:12

I have solved my problem, doing some changes in that case

 when ".xlsx" then Roo::Excelx.new(file.path, packed: nil, file_warning: :ignore)
查看更多
劳资没心,怎么记你
4楼-- · 2019-05-10 00:13

If you look at the documentation, Roo::Excelx.new (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)
查看更多
登录 后发表回答