【问题标题】:how to add spreadsheet column using rubygem 'rodf'?如何使用 ruby​​gem 'rodf' 添加电子表格列?
【发布时间】:2013-03-26 20:07:42
【问题描述】:

我正在尝试将单列开放式办公室电子表格作为 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 是否真的在做任何事情。

【问题讨论】:

  • 等等……这可能奏效了。我认为它在我没有意识到的情况下创建了一个新工作表。

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


【解决方案1】:

这里的总猜测:

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

【讨论】:

    【解决方案2】:

    其实是这样的:

    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
    

    【讨论】:

      猜你喜欢
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多