我想讀取ruby中的excel文件,然後取出數據並將其插入到mysql數據庫中。我使用電子表格:: excel和mysql gems。由於某種原因,我似乎無法能夠使用電子表格的寶石來打開文件進行讀取...這是我的代碼紅寶石excel閱讀器,電子表格gem
require 'rubygems'
require 'spreadsheet'
require 'mysql'
Spreadsheet.client_encoding = 'UTF-8'
book = Spreadsheet.open '/home/data/teams.xlsb'
b1 = book.worksheet('team1')
當我運行該腳本,我得到這個奇怪的錯誤
/usr/local/lib/ruby/gems/1.8/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:376:in `validate!': OLE2 signature is invalid (Ole::Storage::FormatError)
from /usr/local/lib/ruby/gems/1.8/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:368:in `initialize'
from /usr/local/lib/ruby/gems/1.8/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:110:in `new'
from /usr/local/lib/ruby/gems/1.8/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:110:in `load'
from /usr/local/lib/ruby/gems/1.8/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:77:in `initialize'
from /usr/local/lib/ruby/gems/1.8/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:83:in `new'
from /usr/local/lib/ruby/gems/1.8/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:83:in `open'
from /usr/local/lib/ruby/gems/1.8/gems/spreadsheet-0.6.5.8/lib/spreadsheet/excel/reader.rb:1144:in `setup'
from /usr/local/lib/ruby/gems/1.8/gems/spreadsheet-0.6.5.8/lib/spreadsheet/excel/reader.rb:121:in `read'
from /usr/local/lib/ruby/gems/1.8/gems/spreadsheet-0.6.5.8/lib/spreadsheet/excel/workbook.rb:32:in `open'
from /usr/local/lib/ruby/gems/1.8/gems/spreadsheet-0.6.5.8/lib/spreadsheet.rb:62:in `open'
from /usr/local/lib/ruby/gems/1.8/gems/spreadsheet-0.6.5.8/lib/spreadsheet.rb:68:in `open'
from sizes_importer2.rb:7
我在某處看到這個gem可能無法支持.xlsb文件。我不知道這是否是真的,但如果是有人能告訴我如何繞過它,或者如果有什麼不對嗎?我完全失去了,並會感謝任何幫助這個錯誤。謝謝
必須將文件轉換爲2003 xls – Crobos