【发布时间】:2016-09-01 10:16:26
【问题描述】:
所以,一段时间以来,我一直在努力解决这个问题。我知道有很多类似的问题有很好的答案,这些答案我都试过了,但我得到的代码基本上反映了给出的答案。
我正在编写代码来自动为工作表生成匹配的练习。所有这些信息都应该在一个表格中。并且文本应该都与单元格的顶部对齐。
这是我现在拥有的:
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import cm
document = []
doc = SimpleDocTemplate('example.pdf', pagesize=A4, rightMargin=72, leftMargin=72, topMargin=72)
styles = getSampleStyleSheet()
definitions = []
i, a = 1, 65
table = []
for x in range(1, 10):
line = []
line.append(Paragraph(str(i), styles['BodyText']))
line.append(Paragraph('Vocabulary', styles['BodyText']))
line.append(Paragraph(chr(a), styles['BodyText']))
line.append(Paragraph('Often a multi-line definition of the vocabulary. But then, sometimes something short and sweet.', styles['BodyText']))
table.append(line)
i += 1
a += 1
t = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
t.setStyle(TableStyle([
('VALIGN', (1, 1), (-1, -1), 'TOP')
]))
document.append(t)
doc.build(document)
我忽略了什么?
【问题讨论】:
-
喜欢你个人资料中的故事,我希望我高中的老师也能有同样的态度!
-
谢谢!我不得不回去再读一遍,但它仍然是真的。我不会撒谎:今天它给了我几根白发。
标签: python formatting reportlab