在ReportLab中从表格行中删除圆角边框

时间:2018-09-13 05:10:09

标签: reportlab

我知道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)

1 个答案:

答案 0 :(得分: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)

当然,您也必须调整列宽