创建自己的列表样式 caracal rails
Create own list style caracal rails
我使用 caracal gem 从模板创建 docx 文件。
在模板中,我需要如下所示的列表:
- 列表项
1.1 二lv
1.1.1 第三lv
在文档中我找到了创建自己的列表样式的方法。
我把它放在模板的开头 (example.docx.caracal)
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
我的 lict 代码如下所示:
docx.ol do
li 'text'
li do
text 'text'
ol do
li 'text'
li do
text 'Lorem'
ol do
li 'text
end
end
end
end
end
我想念什么?
我找到了答案:
我应该像这样为每个级别定义样式列表:
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
希望对大家有所帮助
我使用 caracal gem 从模板创建 docx 文件。
在模板中,我需要如下所示的列表:
- 列表项 1.1 二lv 1.1.1 第三lv
在文档中我找到了创建自己的列表样式的方法。 我把它放在模板的开头 (example.docx.caracal)
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
我的 lict 代码如下所示:
docx.ol do
li 'text'
li do
text 'text'
ol do
li 'text'
li do
text 'Lorem'
ol do
li 'text
end
end
end
end
end
我想念什么?
我找到了答案:
我应该像这样为每个级别定义样式列表:
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
希望对大家有所帮助