我目前正在使用FPDF将数据输出到表中,但是我遇到了表格单元格包装的问题。
我目前的表格功能如下:
function ImprovedTableCol2($header, $data, $cols ,$colWidth1, $colWidth2, $tableHeader, $closeTable, $fontSize, $icon)
{
// Table Header
if ($tableHeader==true) {
$this->SetFontSize(12);
$this->Cell(90,7,$header[0],1,0,'L');
$this->Cell(90,7,$header[1],1,0,'L');
$this->Ln();
}
// Table body
$this->SetFontSize($fontSize);
$this-> MultiCell(90,6,$data[0],'LRB');
$this->MultiCell(90,6,$data[1],'LRB');
$this->Ln();
}
我的表格页面如下:
$pdf->AddPage();
$pdf->SetFont('Arial','B');
$pdf->SetFontSize(18);
$pdf->Cell(0,10,'Method Statement','B',1,'L');
$pdf->SetFont('');
$pdf->SetFontSize(10);
$pdf->Ln();
$header = array('', '');
$intTotalSCRows = "{method_statement:total_rows}";
$arrSafetyCheck = array();
array_push($arrSafetyCheck, array(
"day" => "{method_statement:day}",
"statement" => "{method_statement:statement}",
"engineer" => "{method_statement:engineer}",
"count" => "{method_statement:count}")
);
foreach ($arrSafetyCheck as $key => $list) {
if ($list['count']=="1") {
$data = array(utf8_decode($list['day']), $list['statement']);
$pdf->ImprovedTableCol2($header,$data,2,130,50,true,false,9,false);
} else if ($list['count']==$intTotalSCRows) {
$data = array(utf8_decode($list['day']), $list['statement']);
$pdf->ImprovedTableCol2($header,$data,2,130,50,false,true,9,false);
} else {
$data = array(utf8_decode($list['day']), $list['statement']);
$pdf->ImprovedTableCol2($header,$data,2,130,50,false,false,9,false);
}
}
MultiCell函数确实包装了文本,但我无法将2个表格列并排放置。
答案 0 :(得分:3)
您需要手动设置单元格的位置(请参阅下面的更新方法)
function ImprovedTableCol2($header, $data, $cols ,$colWidth1, $colWidth2, $tableHeader, $closeTable, $fontSize, $icon)
{
// Table Header
if ($tableHeader==true) {
$this->SetFontSize(12);
$this->Cell(90,7,$header[0],1,0,'L');
$this->Cell(90,7,$header[1],1,0,'L');
$this->Ln();
}
// Table body
$this->SetFontSize($fontSize);
// Get X,Y coordinates
$x = $this->GetX();
$y = $this->GetY();
$this->MultiCell(90,6,$data[0],'LRB');
// update the X coordinate to account for the previous cell width
$x += 90;
// set the XY Coordinates
$this->SetXY($x, $y);
$this->MultiCell(90,6,$data[1],'LRB');
$this->Ln();
}