fpdf表:细胞分裂/合并

时间:2009-08-25 19:38:32

标签: pdf merge split fpdf

我正在尝试生成一个包含分割/合并单元格的表的PDF,如下所示:

细胞|细胞|细胞
细胞| C1 | C2 |细胞
| C1 | C2 |细胞

我正在使用fpdf并且被引用到多单元表脚本,我之前在类似的pdf中使用过它。我查看了代码,无法想出根据我的需要将单元格拆分或合并的方法。有谁知道怎么做?

2 个答案:

答案 0 :(得分:3)

只需手动执行,以便单元格宽度成为两个合并单元格的总和。

根据你的例子:

$column_widths = ["50","50","50","50"];

// First row.
$pdf->Cell($column_widths[0],                     5, "Cell", "", 0, "C", false);
$pdf->Cell($column_widths[1] + $column_widths[2], 5, "Cell", "", 0, "C", false);
$pdf->Cell($column_widths[3],                     5, "Cell", "", 0, "C", false);

// Second row.
$pdf->Cell($column_widths[0], 5, "Cell", "", 0, "C", false);
$pdf->Cell($column_widths[1], 5, "C1",   "", 0, "C", false);
$pdf->Cell($column_widths[2], 5, "C2",   "", 0, "C", false);
$pdf->Cell($column_widths[3], 5, "Cell", "", 0, "C", false);

// Third row.
$pdf->Cell($column_widths[0], 5, "",     "", 0, "C", false);
$pdf->Cell($column_widths[1], 5, "C1",   "", 0, "C", false);
$pdf->Cell($column_widths[2], 5, "C2",   "", 0, "C", false);
$pdf->Cell($column_widths[3], 5, "Cell", "", 0, "C", false);

或类似的东西。

答案 1 :(得分:0)

您可以使用EasyTable https://github.com/fpdf-easytable/fpdf-easytable

一个简单的例子:

$table=new easyTable($pdf, 3, 'width:100;');

 $table->easyCell('Text 1', 'rowspan:2; valign:T'); 
 $table->easyCell('Text 2', 'bgcolor:#b3ccff; rowspan:2');
 $table->easyCell('Text 3');
 $table->printRow();

 $table->rowStyle('min-height:20');
 $table->easyCell('Text 4', 'bgcolor:#3377ff; rowspan:2');
 $table->printRow();

 $table->easyCell('Text 5', 'bgcolor:#99bbff;colspan:2');
 $table->printRow();

 $table->endTable();