Roo出错。任何用于解析.ods文件的gem

时间:2011-06-21 12:33:20

标签: ruby-on-rails-3 openoffice-calc

我正在尝试使用roo gem来解析Openoffice电子表格。但是,我在开始本地主机时遇到以下错误

/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/roo-1.9.3/lib/roo/openoffice.rb:3:in`requirement':没有要加载的文件 - - zip / zipfilesystem(LoadError)

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/roo-1.9.3/lib/roo/openoffice.rb:3:in`'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/roo-1.9.3/lib/roo.rb:68:in`requiret'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/roo-1.9.3/lib/roo.rb:68:in`'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in`requiret'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in,clock(2级)in require'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in` each'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in,clock in require'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in` each'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in`requiret'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler.rb:120:in,requirement'

来自/home/raison/anna/config/application.rb:7:in''

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands.rb:28:in`requiret'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands.rb:28:in,clock in'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands.rb:27:in“tap”

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands.rb:27:in`'

来自script / rails:6:在`require'

来自script / rails:6:在''

我已经安装了rubyzip。有人可以帮我从这里出去吗?另外,请为解析.ods文件建议一些替代宝石。

2 个答案:

答案 0 :(得分:1)

在Gemfile中

gem'rubyzip',:require => '拉链/ zipfilesystem'

答案 1 :(得分:1)

Rspreadsheet允许您阅读,修改和编写ods文件。以下是其基本用法的示例

要求'rspreadsheet'     book = Rspreadsheet.open('./ test.ods')     sheet = book.worksheets(1)

# get value of a cell B5 (there are more ways to do this)
sheet.B5                       # => 'cell value'
sheet[5,2]                     # => 'cell value'
sheet.rows(5).cells(2).value   # => 'cell value'

# set value of a cell B5
sheet.F5 = 'text'
sheet[5,2] = 7
sheet.cells(5,2).value = 1.78

# working with cell format
sheet.cells(5,2).format.bold = true
sheet.cells(5,2).format.background_color = '#FF0000'

# calculating sum of cells in row
sheet.rows(5).cellvalues.sum
sheet.rows(5).cells.sum{ |cell| cell.value.to_f }

# iterating over list of people and displaying the data

total = 0
sheet.rows.each do |row|
  puts "Sponsor #{row[1]} with email #{row[2]} has donated #{row[3]} USD."
  total += row[3].to_f
end
puts "Totally fundraised #{total} USD"

# saving file
book.save
book.save('different_filename.ods')

该项目正在积极开发中,我在我的项目中使用它。欢迎任何评论。如果您要迁移某项功能,可以fill in the request并实施该功能。