我正在用reportlab创建一个表,我要将下表中的单个单元格(向右)对齐:
我要把包含“占领”的单元格向右对齐
这是我的代码:
studentProfileData = [
['Application Form No', ''],
['Name', userData['studentDetails']["firstName"] + " " +userData['studentDetails']["lastName"]],
['Course opted for', userData['courseDetails']["courseOptedFor"]],
['Specific Course Name', courseMapping["Name"]],
['Category', userData['studentDetails']['caste']],
['Religion', userData['studentDetails']['religion']],
['Fathers'+ "'" +'s Name', userData['studentDetails']['religion']],
['Occupation', userData['studentDetails']['fOccupation']],
['Phone No', ""],
['Term', ""]
]
colwidths = [3 * inch, 1.5 * inch, inch]
# Two rows with variable height
rowheights = [.5*inch] * len(studentProfileData)
studentProfile = Table(studentProfileData, colwidths, rowheights, hAlign='LEFT')
studentProfile.setStyle(TableStyle([
('ALIGN', (0, 0), (0, -1), "LEFT"),
('FONTSIZE', (0,0), (-1, -1), 13),
]))
parts = [ page1Head, studentProfile]
为了对齐Reportlab
Table
中的单个单元格,我们需要将TableStyle
更改为以下内容:这是因为我们现在告诉您}之间区域中的单元格应该右对齐,因为该区域中唯一的单元格是包含{}的单元格,只有文本是对齐的。在
(0,7)
和{另一种方法是在表中使用
Paragraph
,而不仅仅是String
,在这种情况下,我们可以使用Paragraph
对齐,因为它将填充单元格的整个宽度。在段落示例
^{pr2}$相关问题 更多 >
编程相关推荐