Reportlab - ListFlowable,从给定的字符串列表生成 Listitem [英] Reportlab - ListFlowable, Generate Listitem from given list of strings

查看:62
本文介绍了Reportlab - ListFlowable,从给定的字符串列表生成 Listitem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一篇 StackOverflow 帖子,所以如果我犯了任何标记错误或类似的错误,我想道歉.

This is my first StackOverflow post so I would like to apologize if I have made any markup mistakes or anything similar.

这是我目前正在进行的项目:我正在开发一个 Django Web 应用程序,它负责根据用户的动态输入生成审计报告.用户可以选择引用文件的变体.

This is the current project I am working on: I am developing a Django web application that's responsible for generating audit reports based on dynamic input by the user. The user will have the option to refer a variation of files.

我目前面临的问题如下:

The current issue I am facing is the following:

我想生成一个列表中给出的静态元素的项目符号列表.这是我目前的代码.

I would like to generate a bulletlist of static elements given in a list. This is the code I have so far.

def generateList(list_of_bullets):
    styles = getSampleStyleSheet()
    t1 = ListFlowable([
         for element in list_of_bullets:
             ListItem(Paragraph(element, styles['Normal']), bulletColor=CMYKColor(0.81,0.45,0.53,0.23), value='circle')
   )], bulletType='bullet', start='circle')
   story.append(t1)

PyCharm 报告 ListFlowable([ <-

PyCharm reports a Expression expected on ListFlowable([ <-

下面的代码工作正常

def get_bullet_list():
    styles = getSampleStyleSheet()
    t1 = ListFlowable([ListItem(Paragraph("Sample Text", styles['Normal']), bulletColor=CMYKColor(0.81, 0.45, 0.53, 0.23), value='circle')], bulletType='bullet', start='circle')

所以我的问题是:有什么方法可以将 ListItems 动态附加到 ListFlowable 中?

So my question is: Is there any way I can dynamically append ListItems to a ListFlowable?

推荐答案

感谢 #python @ irc.freenode.org 上的一位好心用户,我想出了如何动态地做到这一点.

I figured out how to do this dynamically thanks to a kind user on #python @ irc.freenode.org.

以下代码已经过测试并且可以工作.

The following code is tested and works.

def makeBulletList(list):
    styles=getSampleStyleSheet()
    style=styles['Normal']
    table=ListFlowable([ListItem(Paragraph(x, style), leftIndent=35, bulletColor='black', value='circle') for x in list], bulletType='bullet')
    return table

这篇关于Reportlab - ListFlowable,从给定的字符串列表生成 Listitem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆