0

我尝试使用以下代码读取 excel 文件:

require 'rubygems'
require 'parseexcel'
workbook=Spreadsheet::ParseExcel.parse("D:/TEST.xls")

我遇到了以下错误:

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': iconv will be deprecated in the future, use String#encode instead. default formats are encoded in ISO-8859-1
C:/Ruby193/lib/ruby/gems/1.9.1/gems/parseexcel-0.5.2/lib/parseexcel/olestorage.rb:108:in `initialize': No such file or directory - D:/TEST.xls (Errno::ENOENT)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/parseexcel-0.5.2/lib/parseexcel/olestorage.rb:108:in `open'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/parseexcel-0.5.2/lib/parseexcel/olestorage.rb:108:in `initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/parseexcel-0.5.2/lib/parseexcel/parser.rb:173:in `new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/parseexcel-0.5.2/lib/parseexcel/parser.rb:173:in `parse'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/parseexcel-0.5.2/lib/parseexcel/parseexcel.rb:10:in `parse'
from lkc.rb:4:in `<main>'

什么问题,为什么我不能读取 excel 文件?

4

2 回答 2

3

我认为实际的错误信息是这样的,在第二行:

No such file or directory - D:/TEST.xls (Errno::ENOENT)

尝试D:\TEST.xlsD:\\TEST.xls代替。

于 2012-03-06T02:57:32.577 回答
1

标题具有误导性,这个“Iconv 将来会被弃用”并不是真正的问题——它只是一个警告。正如@brandon-tiley 所说,问题在于您尝试打​​开的文件不存在。尝试打开 IRB,然后键入 File.open("D:\Test.xml") 等,直到您没有收到错误消息。然后就知道文件存在并且路径正确,就可以继续调试其他方面了(如果还有错误的话)。

于 2012-03-06T03:50:25.767 回答