2010-07-30 9 views

Odpowiedz

9

Najprostsza funkcja tabela:

table = Table(data, colWidths=270, rowHeights=79) 

Ile kolumn & końcowych rzędów zależy od krotki danych. Wszystkie nasze funkcje tabeli wyglądają następująco:

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 

Spowoduje to utworzenie tabeli 2X2 i wypełnienie jej numerami 1,2,3,4. Następnie możesz utworzyć dokument pliku. W moim przypadku zrobiłem HttpResponse, co jest dość podobne do pliku.