2012-03-06 41 views
0

我嘗試使用此代碼讀取Excel文件被棄用:語言Iconv將在未來

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文件嗎?

回答

3

我認爲實際的錯誤信息是這樣的,在第二行:

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

嘗試D:\TEST.xlsD:\\TEST.xls代替。

+0

是的,它工作正常。謝謝 – user1251207 2012-03-06 13:37:22

+0

但我仍然得到這個未初始化的恆定電子表格(NameError) – user1251207 2012-03-06 13:58:20

1

標題是誤導性的,這個「Iconv將在未來被棄用」不是真正的問題 - 它只是一個警告。正如@ brandon-tilley所說,問題在於您試圖打開的文件不存在。嘗試打開IRB,然後輸入File.open(「D:\ Test.xml」)等,直到您沒有收到錯誤消息。然後你知道文件存在並且路徑是正確的,並且你可以繼續調試其他方面(如果仍有錯誤)。

+2

你瘋了嗎?如果人們開始嘗試使用irb,那麼在stackoverflow中就不會有簡單的問題來回答了......如果主人知道如何使用調試器或pry,他們會幫助我們。 – 2012-03-06 04:22:41

+0

但我得到這個錯誤仍然未初始化常量電子表格(NameError)。這個錯誤即將到來 – user1251207 2012-03-06 13:56:59