Ruby on rails 4 ArgumentError:导入.xlsx文件扩展名时参数数目错误(1..2为3)
我在导入excel文件时遇到问题,当扩展名为.xls时,它工作正常,但当扩展名为.xlsx时,它会给出参数错误Ruby on rails 4 ArgumentError:导入.xlsx文件扩展名时参数数目错误(1..2为3),ruby-on-rails-4,Ruby On Rails 4,我在导入excel文件时遇到问题,当扩展名为.xls时,它工作正常,但当扩展名为.xlsx时,它会给出参数错误 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, fil
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
如果查看文档,Roo::Excelx.new(initialize方法)只接受两个参数 将第6行更改为:
when ".xlsx" then Roo::Excelx.new(file.path, :ignore)
我已经解决了我的问题,在这种情况下做了一些改变
when ".xlsx" then Roo::Excelx.new(file.path, packed: nil, file_warning: :ignore)
试一试
但如果我这样做,它会告诉我“TypeError:没有将符号隐式转换为整数”
Roo::Excel.new(file.path, packed: false, file_warning: :ignore)