我如何克服" Ole :: Storage :: FormatError:OLE2签名无效"重新保存文档时出错是不是一个选项?

时间:2016-12-08 21:53:01

标签: ruby ruby-on-rails-4 spreadsheet xls ole

我正在使用Rails 4.2.7,只是将电子表格gem添加到我的Gemfile

gem 'spreadsheet'

可悲的是,当我对以“.xls”

结尾的文件执行此调用时
    book = Spreadsheet.open file_location

我收到以下错误。不幸的是,不能以另一种Excel格式重新保存此文档(我甚至没有在我的计算机上安装Excel)。我该如何解析这个xls文件?如果能解决问题,我愿意使用另一个宝石。

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'

1 个答案:

答案 0 :(得分:0)

我尝试使用电子表格时遇到了一些问题。那是一段时间以前,所以我不记得究竟发生了什么,但我相信这是一个类似的OLE错误。从那时起它也被更新了。但是,既然你提到你会考虑另一个宝石,我转而使用roo它对我来说效果很好。一个非常强大的好处是它可以处理许多不同的格式,而不仅仅是Excel兼容。