Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reportlab中具有多个级别的编号段落_Reportlab_Paragraph - Fatal编程技术网

Reportlab中具有多个级别的编号段落

Reportlab中具有多个级别的编号段落,reportlab,paragraph,Reportlab,Paragraph,我想在ReportLab中创建一个具有多个级别的编号列表。我几乎找遍了所有地方,我只能找到构建编号列表的标签。但是,当我编写以下代码时,我的列表如下所示: contents.add(Paragraph("<seq/>. Level 1 Header", h1)) contents.add(Paragraph("<seq/>. Level 2 Header", h2)) contents.add(Paragraph("<seq/>. L

我想在ReportLab中创建一个具有多个级别的编号列表。我几乎找遍了所有地方,我只能找到构建编号列表的标签。但是,当我编写以下代码时,我的列表如下所示:

   contents.add(Paragraph("<seq/>. Level 1 Header", h1))
   contents.add(Paragraph("<seq/>. Level 2 Header", h2))    
   contents.add(Paragraph("<seq/>. Level 1 Header", h1))

…这仍然是错误的。我找不到任何保存第一级索引值的内容。

编辑:我现在认为您尝试的操作是不可能的,但我有几个建议

如果您不关心精确的
.
格式,您可以使用多个
seq
标记来实现这一点。要轻松使用多个
seq
标记,请从
seqOrder
开始。它有一个很好的特性,即每当您使用较高级别的seq标记时,较低级别都会重置。为了使您的级别看起来与众不同,我建议对每个级别进行不同的格式设置

contents.add(Paragraph( ('<seqChain order="lev1 lev2"/>'
                         '<seqFormat id="lev1" value="1">'
                         '<seqFormat id="lev2" value="a">'
                         '<seq id="levelOne"/>. Level 1 Header'), h1))
contents.add(Paragraph('<seq id="levelTwo"/> Level 2 Header', h2))    
contents.add(Paragraph('<seq id="levelOne"/>. Level 1 Header', h1))
#We didn't have to reset the level 2 tag because chain takes care of it
contents.add(Paragraph('<seq id="levelTwo"/> Level 2 Header', h2))  
尽管您可以定义一个函数,为您添加一个段落,并手动迭代/重置适当的级别值


我不确定您是否在python中这样做—我知道RML是reportlab商业版的一部分,而且我从未通过添加RML标记来构建文档。但是,如果您使用的是python,那么您可能希望使用
Flowables
构建文档,并且有一个
ListFlowable
来创建这些列表。由于
ListFlowable
仅仅是这些RML标记的一个接口,因此您仍然无法使用所需格式的标签创建列表。您可以在第86页的中了解更多关于
Flowables
,标题索引即使使用id也仍然不正确。我无法在此处查看格式,因此请参见上面的修改。我想这个问题可能有答案:
contents.add(Paragraph( ('<seqChain order="lev1 lev2"/>'
                         '<seqFormat id="lev1" value="1">'
                         '<seqFormat id="lev2" value="a">'
                         '<seq id="levelOne"/>. Level 1 Header'), h1))
contents.add(Paragraph('<seq id="levelTwo"/> Level 2 Header', h2))    
contents.add(Paragraph('<seq id="levelOne"/>. Level 1 Header', h1))
#We didn't have to reset the level 2 tag because chain takes care of it
contents.add(Paragraph('<seq id="levelTwo"/> Level 2 Header', h2))  
level1 = 1
contents.add(Paragraph('{0}. Level 1 Header'.format(level1), h1))
level2 = 1 
contents.add(Paragraph('{0}.{1} Level 2 Header'.format(level1,level2), h2))
#Now we have to automatically increment level1
level1 += 1    
contents.add(Paragraph('{0}. Level 1 Header'.format(level1), h1))
#and manually reset level 2
level2 = 1
contents.add(Paragraph('{0}.{1} Level 2 Header'.format(level1,level2), h2))