如何在ReportLab中创建项目符号列表 [英] How to create a bulleted list in ReportLab
问题描述
如何在ReportLab中创建项目符号列表?该文档令人沮丧地含糊.我正在尝试:
How can I create a bulleted list in ReportLab? The documentation is frustratingly vague. I am trying:
text = ur '''
<para bulletText="•">
item 1
</para>
<para bulletText="•">
item 2
</para>
'''
Story.append(Paragraph(text,TEXT_STYLE))
但是我不断收到类似list index out of range
的错误.看来我一次调用Paragraph()
不能放多个<para></para>
吗?我也尝试设置TEXT_STYLE.bulletText="•"
,但这也不起作用...
But I keep getting errors like list index out of range
. It seems that I can't put more than one <para></para>
in a single call to Paragraph()
? I also tried setting TEXT_STYLE.bulletText="•"
but that doesn't work either...
推荐答案
bulletText参数实际上是Paragraph
对象的构造函数,而不是<para>
标记:-)尝试以下操作:
The bulletText argument is actually a constructor to the Paragraph
object, not the <para>
tag :-) Try this:
story.append(Paragraph(text, TEXT_STYLE, bulletText='-'))
请参阅 ReportLab文档. ReportLab中的约定似乎是使用<bullet>
标记,并且文档确实警告您每个Paragraph
实例只能有一个.我们像这样在ReportLab中渲染项目符号:
Have a look at the examples on page 68 (page 74 now, in 2012) of the ReportLab Documentation, though. The convention in ReportLab seems to be to use the <bullet>
tag, and the docs do warn that you can have only one per Paragraph
instance. We render our bullets in ReportLab like so:
story.append(Paragraph('<bullet>The rain in spain</bullet>', TEXT_STYLE))
这篇关于如何在ReportLab中创建项目符号列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!