使用roo gem写入ruby中的excel文件

Bhu*_*dha 11 ruby excel spreadsheet ruby-on-rails-3

我正在使用Roo gem解析Excel和Excelx文件.但我不知道如何写入这些文件. set_value(row, column, text)方法不起作用.

@oo = Excelx.new('tes.xlsx')
@oo.default_sheet = @oo.sheets.first

def return_column
  keywords = ["website", "url"]
  keywords.each do |keyword|
  1.upto(@oo.last_column) do |n|
  data = @oo.cell(1, n)
  return n if data.downcase=~/#{keyword}/i
end
end
end

def return_rows
  n = return_n
  2.upto(@oo.last_row) do |row|
  data = @oo.cell(row, n)
  stack << data 
 end
end

def appender
  @oo.set_value(1,11, "hey")
end

 appender
Run Code Online (Sandbox Code Playgroud)

我得到的错误信息是

 /.rvm/gems/ruby-1.8.7-p352/gems/roo-1.10.1/lib/roo/generic_spreadsheet.rb:441:in `method_missing': private method `set_value' called for #<Excelx:0x101221f08> (NoMethodError)
from /Users/bhushan/.rvm/gems/ruby-1.8.7-p352/gems/roo-1.10.1/lib/roo/excelx.rb:168:in `method_missing'
from parser.rb:32:in `appender'
from parser.rb:35
Run Code Online (Sandbox Code Playgroud)

har*_*mar 3

在 Excelx 或 OpenOffice 对象中尝试使用“set”方法而不是“set_value”方法。有关更多信息,请参阅 API http://rubydoc.info/gems/roo/1.10.1/frames,我认为 roo gem 专门用于读取 excel 内容而不是写入。例如,使用 set 方法将不会保存回电子表格文件。我认为它节省了缓冲区。尝试一些其他的写作宝石