【问题标题】:Reportlab - ListFlowable, Generate Listitem from given list of stringsReportlab - ListFlowable,从给定的字符串列表生成 Listitem
【发布时间】:2015-10-28 21:23:54
【问题描述】:

这是我的第一篇 StackOverflow 帖子,如果我犯了任何标记错误或类似的事情,我想向您道歉。

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

我目前面临的问题如下:

我想生成列表中给定的静态元素的子弹列表。 这是我目前的代码。

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([

下面的代码运行良好

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 中?

【问题讨论】:

    标签: python reportlab


    【解决方案1】:

    感谢#python @ irc.freenode.org 上的一位好心用户,我想出了如何动态执行此操作。

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-06
      • 2016-04-11
      • 1970-01-01
      • 2011-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多