Reportlab - ListFlowable, Generate Listitem from given list of strings

孤人 提交于 2019-12-12 02:39:57

问题


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

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 reports a Expression expected on ListFlowable([ <-

the code below works just fine

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')

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


回答1:


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


来源:https://stackoverflow.com/questions/33364383/reportlab-listflowable-generate-listitem-from-given-list-of-strings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!