Python 如何在ReportLab中创建简单表格
如何在ReportLab中制作简单表格?我需要制作一个简单的2x20表格并输入一些数据。有人能给我举个例子吗 最简单的表函数:Python 如何在ReportLab中创建简单表格,python,pdf,pdf-generation,Python,Pdf,Pdf Generation,如何在ReportLab中制作简单表格?我需要制作一个简单的2x20表格并输入一些数据。有人能给我举个例子吗 最简单的表函数: table = Table(data, colWidths=270, rowHeights=79) 有多少列和结束行取决于数据元组。我们所有的表函数看起来像: from reportlab.platypus import SimpleDocTemplate from reportlab.platypus.tables import Table cm = 2.54 d
table = Table(data, colWidths=270, rowHeights=79)
有多少列和结束行取决于数据元组。我们所有的表函数看起来像:
from reportlab.platypus import SimpleDocTemplate
from reportlab.platypus.tables import Table
cm = 2.54
def print_pdf(modeladmin, request, queryset):
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
elements = []
doc = SimpleDocTemplate(response, rightMargin=0, leftMargin=6.5 * cm, topMargin=0.3 * cm, bottomMargin=0)
data=[(1,2),(3,4)]
table = Table(data, colWidths=270, rowHeights=79)
elements.append(table)
doc.build(elements)
return response
这将生成表2X2,并用数字1,2,3,4填充。然后你可以制作文件文档。在我的例子中,我做了HttpResponse,这和file差不多