如何使用PHP的FPDF制作像这样的表格?
我似乎无法使用$this->Cell
实现此操作。
如何使用PHP的FPDF制作像这样的表格?
我似乎无法使用$this->Cell
实现此操作。
FPDF 不支持 rowspan
或 colspan
。以下是一个解决方法,您可以尝试使用空单元格和 border
属性来代替,使用 Cell
。
$pdf->Cell(40,5,' ','LTR',0,'L',0); // empty cell with left,top, and right borders
$pdf->Cell(50,5,'Words Here',1,0,'L',0);
$pdf->Cell(50,5,'Words Here',1,0,'L',0);
$pdf->Cell(40,5,'Words Here','LR',1,'C',0); // cell with left and right borders
$pdf->Cell(50,5,'[ x ] abc',1,0,'L',0);
$pdf->Cell(50,5,'[ x ] checkbox1',1,0,'L',0);
$pdf->Cell(40,5,'','LBR',1,'L',0); // empty cell with left,bottom, and right borders
$pdf->Cell(50,5,'[ x ] def',1,0,'L',0);
$pdf->Cell(50,5,'[ x ] checkbox2',1,0,'L',0);
结果将会是 -
我认为我找到了另一种解决方案,以下是我的解决方案,而且不需要空单元格。
$pdf->Cell(40,18,'Words Here', 1,0, 'C');
$x = $pdf->GetX();
$pdf->Cell(40,6,'Words Here', 1,0);
$pdf->Cell(40,6,'Words Here', 1,1);
$pdf->SetX($x);
$pdf->Cell(40,6,'[x] abc', 1,0);
$pdf->Cell(40,6,'[x] Checkbox 1', 1,1);
$pdf->SetX($x);
$pdf->Cell(40,6,'[x] def', 1,0);
$pdf->Cell(40,6,'[x] Checkbox 1', 1,1);
以下是结果:
$this->Cell(40,5,' ','LTR',0,'L',0); // empty cell with left,top, and right borders
$this->Cell(50,5,'111 Here',1,0,'L',0);
$this->Cell(50,5,'222 Here',1,0,'L',0);
$this->Ln();
$this->Cell(40,5,'Solid Here','LR',0,'C',0); // cell with left and right borders
$this->Cell(50,5,'[ o ] che1','LR',0,'L',0);
$this->Cell(50,5,'[ x ] che2','LR',0,'L',0);
$this->Ln();
$this->Cell(40,5,'','LBR',0,'L',0); // empty cell with left,bottom, and right borders
$this->Cell(50,5,'[ x ] def3','LRB',0,'L',0);
$this->Cell(50,5,'[ o ] def4','LRB',0,'L',0);
$this->Ln();
$this->Ln();
$this->Ln();