【问题标题】:Error with Roo . Any gems to parse .ods filesRoo 错误。解析 .ods 文件的任何 gem
【发布时间】:2011-09-19 11:55:26
【问题描述】:

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

/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/roo-1.9.3/lib/roo/openoffice.rb:3:in `require':没有要加载的文件- - 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 `require'

来自/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 `require'

来自 /home/raison/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `block (2 levels) 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 `block 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 `require'

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

来自 /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 `require'

来自/home/raison/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands.rb:28:in `block 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 `'

来自脚本/rails:6:in `require'

来自脚本/rails:6:in `'

我已经安装了 ruby​​zip。有人可以帮我从这里出去吗?还请建议一些用于解析 .ods 文件的备用 gem。

【问题讨论】:

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


    【解决方案1】:

    在 Gemfile 中

    gem 'rubyzip', :require => 'zip/zipfilesystem'

    【讨论】:

      【解决方案2】:

      Rspreadsheet 允许您读取、修改和写入 ods 文件。这是它的基本用法示例

      require 'rspreadsheet'
      
      # initialization
      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')
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-01-14
        • 1970-01-01
        • 2012-03-24
        • 2020-08-09
        • 1970-01-01
        • 2018-08-16
        • 2019-12-09
        相关资源
        最近更新 更多