如何使用rubygem'rodf'添加电子表格列?

时间:2013-03-26 20:07:43

标签: ruby rubygems openoffice.org openoffice-calc rodf

我正在尝试将一列开放式办公电子表格作为ruby脚本的输入,并为该列旁边的列中的每个单元格写一个结果。所以,举例说明:

输入:

   A
--------
1| XXX |
--------
2| YYY |

输出:

     A |  B
-------------------
1| XXX | result1  |
-------------------
2| YYY | result 2 |

我正在尝试使用rodf ruby​​gem来完成此任务,但我无法弄清楚如何创建新列。

 ss.table 'My first table from Ruby' do
   row { cell 'Hello, rODF world!' }
   row { cell 'next?'
 end

会写'下一个吗?'到第一个下面的单元格(即A2)。

当我尝试这个时,我得到一个例外:

ss.table 'My first table from Ruby' do
   row { cell 'Hello, rODF world!' }
   column { row { cell 'wtf?' } }
end
NoMethodError: undefined method `row' for #<ODF::Column:0x00000000f4c2c0 @elem_attrs={}>
from (irb):35:in `block (2 levels) in irb_binding'
from (eval):4:in `instance_eval'
from (eval):4:in `column'
from (irb):35:in `block in irb_binding'
from (eval):4:in `instance_eval'
from (eval):4:in `table'
from (irb):33
from /usr/bin/irb:12:in `<main>'

如何访问B列中的单元格?

文档不清楚,我无法从源代码中看出column.rb实际上是在做什么。

2 个答案:

答案 0 :(得分:0)

总猜:

ss.table 'My first table from Ruby' do
   row { cell 'Hello, rODF world!', 'next?' }
end

答案 1 :(得分:0)

所以它实际上是这样的:

ss.table 'My first table from Ruby' do
  row do
    cell 'This goes into A1'
    cell 'This goes into B1'
    cell 'This goes into C1'
    cell 'And on, and on, and on...'
  end
  row do # this starts a new row
    cell 'This goes into A2'
    cell 'This goes into B2'
    cell 'Got it? ;-)'
  end
end