从ReportLab中的表行中删除圆角边框

问题描述 投票:0回答:1

我知道ReportLab可以选择使用'linejoin'和'linecap'设置来修改线条。

对于表格,LINEBEFORE或LINEAFTER命令将在表格上放置一条水平线,分隔两列。

有没有办法让这条线没有圆边?它默认为圆边。

这段代码将成为一个示例表。如何将红色垂直线设为没有圆边的矩形?或者解决方案是在列之间添加一个细柱并用红色填充。

from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, inch
from reportlab.platypus import Image, Paragraph, SimpleDocTemplate, Table
from reportlab.lib.styles import getSampleStyleSheet

doc = SimpleDocTemplate("delete_me.pdf", pagesize=letter)
# container for the 'Flowable' objects
elements = []

styleSheet = getSampleStyleSheet()


P0 = Paragraph('''
               <b>A pa<font color=red>r</font>a<i>graph</i></b>
               <super><font color=yellow>1</font></super>''',
               styleSheet["BodyText"])
P = Paragraph('''
    <para align=center spaceb=3>The <b>ReportLab Left
    <font color=red>Logo</font></b>
    Image</para>''',
    styleSheet["BodyText"])
data= [['A', 'B', 'C', P, 'D'],
       ['00', '01', '02', P, '04'],
       ['10', '11', '12', P, '14'],
       ['20', '21', '22', '23', '24'],
       ['30', '31', '32', '33', '34']]

t=Table(data,style=[('LINEBEFORE',(2,1),(2,-2),6,colors.pink)]
)
t._argW[3]=1.5*inch

elements.append(t)
# write the document to disk
doc.build(elements)
reportlab
1个回答
0
投票

这不是一个完美的答案,但是在左侧制作一些细胞并填充它们可以解决问题

from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, inch
from reportlab.platypus import Image, Paragraph, SimpleDocTemplate, Table
from reportlab.lib.styles import getSampleStyleSheet

doc = SimpleDocTemplate("delete_me.pdf", pagesize=letter)
# container for the 'Flowable' objects
elements = []

styleSheet = getSampleStyleSheet()


P0 = Paragraph('''
               <b>A pa<font color=red>r</font>a<i>graph</i></b>
               <super><font color=yellow>1</font></super>''',
               styleSheet["BodyText"])
P = Paragraph('''
    <para align=center spaceb=3>The <b>ReportLab Left
    <font color=red>Logo</font></b>
    Image</para>''',
    styleSheet["BodyText"])
data= [['A', 'B', 'C', P, 'D'],
       ['00', '01', '02', P, '04'],
       ['10', '11', '12', P, '14'],
       ['20', '21', '22', '23', '24'],
       ['30', '31', '32', '33', '34']]

for i in range(len(data)): # Create slim invisible column
    data[i] = [' '] + data[i]

t=Table(data,style=[
         ('BACKGROUND', (0,1), (0,-2), colors.pink),
        ('LINEBEFORE',(2,1),(2,-2),6,colors.pink)
])
t._argW[3]=1.5*inch

elements.append(t)
# write the document to disk
doc.build(elements)

当然,您还必须调整列宽

© www.soinside.com 2019 - 2024. All rights reserved.