3

我正在尝试在 Ruby On Rails 中读取 Excel 文件。我已经完成了这样的编码,用于从 Excel 工作表中读取单元格内容。

def test
 require 'rubygems'
 require 'iconv'
 require 'roo'

 s = Excel.new("C:/Sites/hmmsapp/Book1.xls")
 s.default_sheet = s.sheets.first

 1.upto(4) do |line|
   roll = s.cell(line,'A')
   puts "#{roll} -------------"
 end
end

但是在运行它时它总是给我这个错误。

NameError in HostelController#test

uninitialized constant HostelController::Excel

我还iconv根据针对此问题的建议包括在内。但是错误没有变化。请注意消除此错误并正确读取 excel 文件。

4

1 回答 1

11

尝试Roo::Excel.new

或者Roo::Spreadsheet.new

于 2013-03-25T07:32:36.223 回答