Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为表的偶数行和奇数行定义样式(python reportlab)_Python_Reportlab - Fatal编程技术网

如何为表的偶数行和奇数行定义样式(python reportlab)

如何为表的偶数行和奇数行定义样式(python reportlab),python,reportlab,Python,Reportlab,我必须打印一份长达数百行的报告。其特殊性在于,每一项的内容都应打印在两行上。这些线条有特定的风格 样本: line 1 : First Header line line 2 : Second Header line line 3 : Name , adress line 4 : birth date , gender, hobbies line 5 : Name , adress line 6 : birth date , gender, hobbies ... 我使用表来处理每页的内

我必须打印一份长达数百行的报告。其特殊性在于,每一项的内容都应打印在两行上。这些线条有特定的风格

样本:

line 1 : First Header line 
line 2 : Second Header line 
line 3 : Name , adress
line 4 : birth date , gender, hobbies 
line 5 : Name , adress
line 6 : birth date , gender, hobbies 
...
我使用表来处理每页的内容

在样式定义中,我有如下内容:

('FONTSIZE',(0,2),(-1,-1),18)
但是我希望这个样式适用于所有偶数行,并且像这样的样式

('FONTSIZE',(0,2),(-1,1),12)
适用于所有赔率行


最好是这两种样式适用于整个表,但第一行和第二行除外,这两行包含表的标题。

您可以使用代码根据行号生成表样式。Reportlab确实有一个内置功能,可以在用户手册中自动为行和颜色交替使用背景色,查找ROWBACKGROUNDS和COLBACKGROUNDS,但对于任意样式,您必须通过循环数据行来执行以下自定义操作

table_style = [...]

for i, row in enumerate(table_rows):
  if i % 2 == 0:
    table_style.append(('FONTSIZE',(0,i),(-1,i),18))
  else:
    table_style.append(('FONTSIZE',(0,i),(-1,i),12))

my_table.setStyle(TableStyle(table_style))

您可以通过使用基于行号生成表格样式的代码来实现这一点。Reportlab确实有一个内置功能,可以在用户手册中自动为行和颜色交替使用背景色,查找ROWBACKGROUNDS和COLBACKGROUNDS,但对于任意样式,您必须通过循环数据行来执行以下自定义操作

table_style = [...]

for i, row in enumerate(table_rows):
  if i % 2 == 0:
    table_style.append(('FONTSIZE',(0,i),(-1,i),18))
  else:
    table_style.append(('FONTSIZE',(0,i),(-1,i),12))

my_table.setStyle(TableStyle(table_style))

有一个错误。正确的代码:my_table.setStyletable_style有一个错误。正确的代码:my_table.setStyletable_style