Search code examples
rubyruby-on-rails-4spreadsheetxlsole

How do I overcome "Ole::Storage::FormatError: OLE2 signature is invalid" error when re-saving the doc is not an option?


I’m using Rails 4.2.7 and just added the spreadsheet gem to my Gemfile

gem 'spreadsheet'

Sadly, when I execute this call against a file that ends in “.xls”

    book = Spreadsheet.open file_location

I get the below error. Unfortunately, it is not an option to resave this document in another Excel format (I don’t even have Excel installed on my computer). How can I parse this xls file? I’m open to using another gem if it solves the problem.

Ole::Storage::FormatError: OLE2 signature is invalid
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:378:in `validate!'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:370:in `initialize'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:112:in `new'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:112:in `load'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:79:in `initialize'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:85:in `new'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:85:in `open'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/spreadsheet-1.1.4/lib/spreadsheet/excel/reader.rb:1282:in `setup'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/spreadsheet-1.1.4/lib/spreadsheet/excel/reader.rb:140:in `read'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/spreadsheet-1.1.4/lib/spreadsheet/excel/workbook.rb:32:in `open'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/spreadsheet-1.1.4/lib/spreadsheet.rb:67:in `open'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/spreadsheet-1.1.4/lib/spreadsheet.rb:73:in `open'
    from /Users/davea/Documents/workspace/myproject/app/services/xls_to_my_object_times_converter_service.rb:12:in `get_my_object_times'
    from /Users/davea/Documents/workspace/myproject/app/services/xls_processor_service.rb:15:in `process_page_data'
    from /Users/davea/Documents/workspace/myproject/app/services/abstract_import_service.rb:82:in `process_my_object_data'
    from (irb):3
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/console.rb:110:in `start'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/console.rb:9:in `start'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'

Solution

  • I had some problems with spreadsheet when I tried it. That was some time ago, so I don't recall exactly what happened but I believe it was a similar OLE error. It has been updated since then, as well. But, since you mentioned you would consider another gem, I switched to roo and it has worked quite well for me. One very strong benefit is that it can handle many different formats, not just Excel-compatible.