我正在使用reportlab(与Django一起)创建PDF。我创建了以下用于创建带有头部和细节的表的代码:
elements = []
datas = []
course_info = [
['Course Code' , c.course_code] ,
['Course Title' , c.course_name],
['Prerequisites by Course(s) and Topics', c.pre_reqs],
['Assessment Instruments with Weights (some desc)', c.grade_distribution]
]
for k in course_info:
headpara = Paragraph(k[0], styleB)
datas.append([headpara , Paragraph(clean_string(k[1]), styleN)])
t = LongTable(datas, colWidths=[5 * cm, 12 * cm])
t.setStyle(TableStyle(org.getTableStyle()))
elements.append(t)
doc.build(elements)
我正在使用BaseDocTemplate作为我的模板。 我想要的是能够将headpara
的部分内容视为非粗体,例如第四行中的(some desc)
部分需要是普通样式而不是粗体。我如何实现这一目标?
答案 0 :(得分:5)
Reportlab支持简单的HTML格式化,因此我们可以使用styleN
并使所需的文本变为粗体。像这样:
course_info = [
['<b>Course Code</b>' , c.course_code] ,
['<b>Course Title</b>' , c.course_name],
['<b>Prerequisites by Course(s) and Topics</b>', c.pre_reqs],
['<b>Assessment Instruments with Weights</b> (some desc)', c.grade_distribution]
]
for k in course_info:
headpara = Paragraph(k[0], styleN)
datas.append([headpara , Paragraph(clean_string(k[1]), styleN)])