当前位置: 首页>>代码示例>>Python>>正文


Python Table.split方法代码示例

本文整理汇总了Python中reportlab.platypus.Table.split方法的典型用法代码示例。如果您正苦于以下问题:Python Table.split方法的具体用法?Python Table.split怎么用?Python Table.split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.platypus.Table的用法示例。


在下文中一共展示了Table.split方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_maps_lookup_pages

# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import split [as 别名]
def get_maps_lookup_pages(app_handle, dwellingsHandle, membership_list):
    church_use_text = '%s - For Church Use Only' % app_handle.unit_unitname
    church_flowable = Paragraph(church_use_text, styles['DaveFooter'])
    pages = []
    mbr_dwellings_dict = make_member_dwellings_dict(dwellingsHandle,
                                                    membership_list)
    table_data = [['#', 'Name']]
    # we are confident that this has already been sorted by map index
    for dwell_counter in xrange(len(dwellingsHandle.dwellingList)):
        dwelling = dwellingsHandle.dwellingList[dwell_counter]
        print "Dwelling: %s %s" % (dwelling.mapIndex, dwelling)
        mbrs = mbr_dwellings_dict.get(dwell_counter, [])
        print "Members: %s" % str(mbrs)
        mbr_str = '\n'.join(
            ['%s%s' % ('' if x.isMember else '*', x.coupleName) for x in mbrs])
        table_data.append([dwell_counter + 1, mbr_str])
    map_idx_width = 0.3 * inch
    name_width = STANDARD_TABLE_WIDTH - map_idx_width
    this_tbl = Table(
        data=table_data,
        colWidths=[map_idx_width, name_width],
        style=TableStyle([('GRID', (0, 0), (-1, -1), 0.25, colors.black),
                          ('FONTSIZE', (0, 0), (-1, -1), 8),
                          ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                          ('ALIGNMENT', (0, 0), (0, -1), 'CENTRE'),
                         ]),
        repeatRows=1)
    result = this_tbl.split(STANDARD_TABLE_WIDTH, STANDARD_TABLE_HEIGHT)
    broken_down_tbls = []
    while len(result) == 2:
        broken_down_tbls.append(result[0])
        result = result[1].split(STANDARD_TABLE_WIDTH, STANDARD_TABLE_HEIGHT)
    broken_down_tbls.append(result[0])
    while len(broken_down_tbls):
        dir_page = DirectoryPage()
        dir_page.flowables.append('CURRENT_PAGE_NUMBER')
        table_data = [broken_down_tbls[:2]]
        if len(table_data[0]) == 1:
            table_data[0].append([])
        table_data[0].insert(1, [])
        broken_down_tbls = broken_down_tbls[2:]
        col_widths = [STANDARD_TABLE_WIDTH, STANDARD_MARGIN,
                      STANDARD_TABLE_WIDTH]
        dir_page.flowables.append(
            Table(data=table_data,
                  colWidths=col_widths,
                  style=TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP'),])))
        dir_page.flowables.append(church_flowable)
        pages.append(dir_page)
    return pages
开发者ID:dlernstrom,项目名称:Ward-Directory-Creator,代码行数:52,代码来源:MapsPages.py

示例2: exportpdf

# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import split [as 别名]
def exportpdf(request, setname):
    (PAGEW, PAGEH) = request.session['reportpagesize']
    data = request.session[setname]
    try:
        name = request.session['reportname']
    except KeyError:
        name = 'report'
    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename='+slugify(name)+'.pdf'
    GRID_STYLE = TableStyle(
                    [('GRID', (0,0), (-1,-1), 0.25, colors.black),
                     ('ALIGN',(0,0),(-1,0),'CENTER'),]
                    )
    doc = SimpleDocTemplate( response, pagesize = (PAGEW*inch, PAGEH*inch), leftMargin = 0.5*inch, rightMargin = 0.5*inch, topMargin = 0.5*inch, bottomMargin = 0.5*inch )
    Story = [ ]
    # Add the table
    t = Table( data )
    t.setStyle( GRID_STYLE )
    for s in t.split((PAGEW-1)*inch, (PAGEH-1.15)*inch):
        Story.append( s )
        Story.append( Spacer( 1, 0.15*inch ) )
    doc.build( Story )
    return response
开发者ID:emperorcezar,项目名称:OpenConnect,代码行数:25,代码来源:views.py

示例3: old_tables_test

# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import split [as 别名]

#.........这里部分代码省略.........
     ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))]
    )
    t.setStyle(ts)
    lst.append(Paragraph("This is a custom style\n", styleSheet['BodyText']))
    lst.append(t)
    lst.append(Paragraph("""
    It was created as follows:
    """, styleSheet['BodyText']))
    lst.append(Preformatted("""
   ts = TableStyle(
    [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
     ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
     ('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'),
     ('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'),
     ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
     ('TEXTCOLOR', (0,1), (0,-1), colors.red),
     ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))]
    )
    """, styleSheet['Code']))
    data = (
        ('', 'Jan\nCold', 'Feb\n', 'Mar\n','Apr\n','May\n', 'Jun\nHot', 'Jul\n', 'Aug\nThunder', 'Sep\n', 'Oct\n', 'Nov\n', 'Dec\n'),
        ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
        ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
        ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
        ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
        )
    c = list(colwidths)
    c[0] = None
    c[8] = None
    t = Table(data, c, [None]+list(rowheights[1:]))
    t.setStyle(LIST_STYLE)
    lst.append(Paragraph("""
        This is a LIST_STYLE table with the first rowheight set to None ie automatic.
        The top row cells are split at a newline '\\n' character. The first and August
        column widths were also set to None.
    """, styleSheet['BodyText']))
    lst.append(t)

    lst.append(Paragraph("""
        This demonstrates a number of features useful in financial statements. The first is decimal alignment;
        with ALIGN=DECIMAL the numbers align on the points; and the points are aligned based on
        the RIGHTPADDING, which is usually 3 points so you should set it higher.  The second is multiple lines;
        one can specify double or triple lines and control the separation if desired. Finally, the coloured
        negative numbers were (we regret to say) done in the style; we don't have a way to conditionally
        format numbers based on value yet.
    """, styleSheet['BodyText']))


    t = Table([[u'Corporate Assets','Amount'],
               ['Fixed Assets','1,234,567.89'],
               ['Company Vehicle','1,234.8901'],
               ['Petty Cash','42'],
               [u'Intellectual Property\u00ae','(42,078,231.56)'],
               ['Overdraft','(12,345)'],
               ['Boardroom Flat Screen','60 inches'],
               ['Net Position','Deep Sh*t.Really']
               ],
              [144,72])

    ts = TableStyle(
        [#first the top row
         ('ALIGN', (1,1), (-1,-1), 'CENTER'),
         ('LINEABOVE', (0,0), (-1,0), 1, colors.purple),
         ('LINEBELOW', (0,0), (-1,0), 1, colors.purple),
         ('FONT', (0,0), (-1,0), 'Times-Bold'),
开发者ID:jeffery9,项目名称:reportlab,代码行数:69,代码来源:test_platypus_tables.py

示例4: generateEventParticipationPDF

# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import split [as 别名]
def generateEventParticipationPDF(department_id):
    """
    Generates and returns a PDF containing the DTV Summary (by venue).
    Accessible by cores only.
    """

    try:
        department = Department.objects.get(id = int(department_id))
    except Department.DoesNotExist:
        raise Http404('Department not found.')

    participantsList = department.participants.all()
    if not participantsList:
        return HttpResponse('The event has no participants.')

    # Create the HttpResponse object with the appropriate PDF headers.

    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = \
        'attachment; filename=%s-participation-summary.pdf' % event.title

    # Create the PDF object, using the response object as its "file."

    pdf = canvas.Canvas(response, pagesize=A4)

    # Define the title of the document as printed in the document header.

    doc_title = '%s Participation Summary' % event.title

    # Get the width and height of the page.

    (A4Width, A4Height) = A4

    # Page number

    pageNo = 1

    # Setting x to be a cm from the left edge

    x = cm
    
    # Paint the headers and get the coordinates
    y = initNewPDFPage(pdf, doc_title, pageNo, A4)

    # Construct the table data

    tableData = [[
        'S.No.',
        'Name',
        'Shaastra ID',
        'Gender',
        'Age',
        'Branch',
        'Mobile',
        'College',
        ]]
    sNo = 0
    for participant in participantsList:
        sNo += 1
        tableData.append([
            sNo,
            participant.name,
            participant.shaastra_id,
            participant.gender,
            participant.age,
            participant.branch,
            participant.mobile_number,
            participant.college,
            ])

    t = Table(tableData, repeatRows=1)

    # Set the table style

    tableStyle = TableStyle([  # Font style for Table Data
                               # Font style for Table Header
        ('FONTNAME', (0, 1), (-1, -1), 'Times-Roman'),
        ('FONTNAME', (0, 0), (-1, 0), 'Times-Bold'),
        ('FONTSIZE', (0, 0), (-1, -1), 12),
        ('ALIGN', (0, 0), (-1, -1), 'CENTRE'),
        ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
        ('GRID', (0, 0), (-1, -1), 1, colors.black),
        ])
    t.setStyle(tableStyle)
    
    availableWidth = A4Width - 2 * cm  # Leaving margins of 1 cm on both sides
    availableHeight = y
    tableSplit = t.split(availableWidth, availableHeight)  # find required space
    for splitPortion in tableSplit:
        (tableWidth, tableHeight) = splitPortion.wrap(availableWidth, availableHeight)
        splitPortion.drawOn(pdf, x, y - tableHeight)
        pdf.showPage()
        pageNo += 1
        if tableSplit[-1] != splitPortion:  # If it is not the last iteration.
            y = initNewPDFPage(pdf, doc_title, pageNo, A4)  # There are more pages. Paint the header.
        
    pdf.save()

    return response
开发者ID:ShaastraWebops,项目名称:ERP,代码行数:101,代码来源:eventParticipationPDF.py

示例5: DelayedTable

# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import split [as 别名]
class DelayedTable(Table):

    """
    A flowable that inserts a table for which it has the data.

    Needed so column widths can be determined after we know on what frame
    the table will be inserted, thus making the overal table width correct.
    """

    def __init__(self, data, colWidths, style=None, repeatrows=False, splitByRow=True):
        self.data = data
        self._colWidths = colWidths
        if style is None:
            style = TableStyle([
                ('LEFTPADDING', (0, 0), (-1, -1), 0),
                ('RIGHTPADDING', (0, 0), (-1, -1), 0),
                ('TOPPADDING', (0, 0), (-1, -1), 0),
                ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
                ])
        self.style = style
        self.t = None
        self.repeatrows = repeatrows
        self.hAlign = TA_CENTER
        self.splitByRow = splitByRow

        # # Try to look more like a Table
        # self._ncols = 2
        # self._nosplitCmds= []
        # self._nrows= 1
        # self._rowHeights= [None]
        # self._spanCmds= []
        # self.ident= None
        # self.repeatCols= 0
        # self.repeatRows= 0
        # self.splitByRow= 1
        # self.vAlign= 'MIDDLE'

    def wrap(self, w, h):
        # Create the table, with the widths from colWidths reinterpreted
        # if needed as percentages of frame/cell/whatever width w is.

        # _tw = w/sum(self.colWidths)
        def adjust(*args, **kwargs):
            kwargs['total'] = w
            return styles.adjustUnits(*args, **kwargs)
        # adjust=functools.partial(styles.adjustUnits, total=w)
        self.colWidths = list(map(adjust, self._colWidths))
        # colWidths = [_w * _tw for _w in self.colWidths]
        self.t = Table(self.data, colWidths=self.colWidths,
            style=self.style, repeatRows=self.repeatrows,
            splitByRow=True)
            # splitByRow=self.splitByRow)
        self.t.hAlign = self.hAlign
        return self.t.wrap(w, h)

    def split(self, w, h):
        if self.splitByRow:
            if not self.t:
                self.wrap(w, h)
            return self.t.split(w, h)
        else:
            return []

    def drawOn(self, canvas, x, y, _sW=0):
        self.t.drawOn(canvas, x, y, _sW)

    def identity(self, maxLen=None):
        return "<%s at %s%s%s> containing: %s" % (
            self.__class__.__name__,
            hex(id(self)), self._frameName(),
            getattr(self, 'name', '') and
                (' name="%s"' % getattr(self, 'name', '')) or '',
            str(self.data[0])[:180]
        )
开发者ID:aquavitae,项目名称:rst2pdf-py3-dev,代码行数:76,代码来源:flowables.py


注:本文中的reportlab.platypus.Table.split方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。