Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby excel reader, spreadsheet gem

i am trying to read an excel file in ruby and then take the data and insert it into a mysql database. I am using the spreadsheet::excel and mysql gems. for some reason i cannot seem to be able to use the spreadsheet gem to open the file for reading... this is my code

require 'rubygems'
require 'spreadsheet'
require 'mysql'

Spreadsheet.client_encoding = 'UTF-8'

book = Spreadsheet.open '/home/data/teams.xlsb'

b1 = book.worksheet('team1')

i get this weird error when i run the script

/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

i read somewhere that this gem might not be able to support the .xlsb files. i do not know if this is true or not but if it is can someone tell me how to go around it, or if there is something else wrong? i am utterly lost and would appreciate any help with this error. thank you

like image 688
Crobos Avatar asked Sep 02 '11 08:09

Crobos


1 Answers

Did you already take a look to roo? -> http://rubygems.org/gems/roo

like image 62
knut Avatar answered Sep 22 '22 16:09

knut