【问题标题】:ruby excel reader, spreadsheet gemruby excel 阅读器,电子表格 gem
【发布时间】:2011-09-02 08:14:16
【问题描述】:

我正在尝试读取 ruby​​ 中的 excel 文件,然后获取数据并将其插入 mysql 数据库。我正在使用电子表格::excel 和 mysql gems。由于某种原因,我似乎无法使用电子表格 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

标签: mysql ruby excel gem spreadsheet


【解决方案1】:

你已经看过 roo 了吗? -> http://rubygems.org/gems/roo

【讨论】:

  • @barbolo:看起来 xlsx 支持不起作用,但您应该使用 Excelx.new <path> 加载它。像魅力一样工作。
  • 我不得不投反对票。就像在 Linux 上寻求帮助并被告知要使用 Windows。
  • .xlsb 在 roo 自述文件中未列为受支持的格式。
猜你喜欢
  • 2019-01-11
  • 1970-01-01
  • 1970-01-01
  • 2020-02-22
  • 1970-01-01
  • 2021-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多