你如何使用 PHP 用 FPDF 制作这样的表格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13407085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you make a table like this with FPDF using PHP?
提问by Heather McVay
How do you make a table like this with FPDF using PHP?
你如何使用 PHP 用 FPDF 制作这样的表格?
I can't seem to figure out how to do this with $this->Cell.
我似乎无法弄清楚如何使用$this->Cell.


回答by Sean
FPDF does not recognize rowspanor colspan. Here is a workaround that you can try, using empty cells and the borderattribute for 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);
and the result would be -

结果是——

回答by Heather McVay
Thanks, that helped, this worked for me:
谢谢,这有帮助,这对我有用:
$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();
回答by syamcode
I think i found other solution, here is my solution without empty cell needed.
我想我找到了其他解决方案,这是我的解决方案,不需要空单元格。
$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);
And here is the result:
结果如下:

