创建自己的列表样式caracal rails

时间:2018-01-31 22:57:16

标签: ruby-on-rails openxml caracal

我使用caracal gem从模板创建docx文件。

在模板中,我需要一个如下所示的列表:

  1. 列出项目 1.1第二个lv  1.1.1第三次lv
  2. 在文档中,我找到了如何创建自己的列表样式。 我把它放在模板的开头(example.docx.caracal)

      var cost = (x * .1) +  Number(x);
      console.log(cost);
    

    我的lict代码如下:

    docx.list_style do
      type    :ordered    # sets the type of list. accepts :ordered or :unordered.
      level   3           # sets the nesting level. 0-based index.
      format  'decimal'   # sets the list style. see OOXML docs for details.
      value   '%1.%2.%3.' # sets the value of the list item marker. see OOXML docs for details.
      align   :left       # sets the alignment. accepts :left, :center: and :right. defaults to :left.
      indent  400         # sets the indention of the marker from the margin. units in twips.
      left    800         # sets the indention of the text from the margin. units in twips.
      start   1           # sets the number at which item counts begin. defaults to 1.
      restart 1           # sets the level that triggers a reset of numbers at this level. 1-based index. 0 means numbers never reset. defaults to 1.
    end
    

    我想念的是什么?

1 个答案:

答案 0 :(得分:0)

我找到了答案:

我应该为每个级别定义样式列表,如下所示:

docx.list_style do
  type :ordered   
  level 0
  format 'decimal'
  value '%1.'
  left 360
  indent 180
end
docx.list_style do
  type :ordered   
  level 1
  format 'decimal' 
  value '%1.%2.' #show number like 1.1
  left 720
  indent 360
end
docx.list_style do
  type :ordered   
  level 2
  format 'lowerLetter' # can use decimal, lowerLetter or lowerRoman
  value '%3.' # show me only letter
  left 720
  indent 540
end

我希望它会帮助某人