使用FPDF的多单元

时间:2016-02-04 02:07:27

标签: php fpdf

我正在创建一个包含七(7)列的表:

PEDIDO | CANTIDAD | PENDIENTE | UNIDAD | DESCRIPCION | COSTO | NETO

这是我用来填充表格的循环:

do { 


    $pdf->Cell(20, 8,$row_Recordset11['ordered'], 0,0,'C');
    $pdf->Cell(20, 8,$row_Recordset11['quantity'], 0,0,'C');
    $pdf->Cell(20, 8,$row_Recordset11['pending'], 0,0,'C');

if ($row_Recordset11['material_or_service'] == 1){
    $pdf->Cell(20, 8, $row_Recordset11['unit_name'], 0,0,"C");


$cell_width = 70;
$current_y = $pdf->GetY();
$current_x = $pdf->GetX();

$pdf->MultiCell($cell_width, 8, $row_Recordset11['material_name'],0,"L", 0);

$pdf->SetXY($current_x + $cell_width, $current_y);
$current_x = $pdf->GetX();

}
if ($row_Recordset11['material_or_service'] == 2){
    $pdf->Cell(20, 8, $row_Recordset11['unit_name'], 0,0,"C");


$cell_width = 70;
$current_y = $pdf->GetY();
$current_x = $pdf->GetX();

$pdf->MultiCell($cell_width, 8, $row_Recordset11['service_name'],0,"L", 0);

$pdf->SetXY($current_x + $cell_width, $current_y);
$current_x = $pdf->GetX();

}
    $pdf->Cell(20, 8, "$ ".number_format($row_Recordset11['cost'], 2) , 0,0,'R');
    $pdf->Cell(20, 8, "$ ".number_format($row_Recordset11['net'], 2) , 0,0,'R');



    $pdf->Ln(4);
    } while ($row_Recordset11 = mysql_fetch_assoc($Recordset11)); 

正如您所看到的,MultiCell()对象填充的唯一列是DESCRIPCION列。

我没有得到我需要的结果。在这种情况下,第一行和第二行对象在列DESCRIPCION中有两行,但正如您在附加图像中看到的那样,两行打印出来,但第二和第三对象不会在我的下面开始预期...

enter image description here

欢迎任何帮助......

1 个答案:

答案 0 :(得分:1)

我已按如下方式解决了这个问题:

do { 

$current_y = $pdf->GetY();
$current_x = $pdf->GetX();
$current_y2 = $current_y;
$current_x2 = $current_x;
    $pdf->Cell(20, 8,$row_Recordset11['ordered'], 0,0,'C');
    $pdf->Cell(20, 8,$row_Recordset11['quantity'], 0,0,'C');
    $pdf->Cell(20, 8,$row_Recordset11['pending'], 0,0,'C');

if ($row_Recordset11['material_or_service'] == 1){
    $pdf->Cell(20, 8, $row_Recordset11['unit_name'], 0,0,"C");


$cell_width = 70;
$current_x2 = $pdf->GetX();

$pdf->MultiCell($cell_width, 8, $row_Recordset11['material_name'],0,"L", 0);

$current_y2 = $pdf->GetY();


}


if ($row_Recordset11['material_or_service'] == 2){
    $pdf->Cell(20, 8, $row_Recordset11['unit_name'], 0,0,"C");


$cell_width = 70;
$current_x2 = $pdf->GetX();

$pdf->MultiCell($cell_width, 8, $row_Recordset11['service_name'],0,"L", 0);

$current_y2 = $pdf->GetY();


}



$pdf->SetXY($current_x2 + $cell_width, $current_y);


    $pdf->Cell(20, 8, "$ ".number_format($row_Recordset11['cost'], 2) , 0,0,'R');
    $pdf->Cell(20, 8, "$ ".number_format($row_Recordset11['net'], 2) , 0,0,'R');

$pdf->SetXY($current_x, $current_y2);


    } while ($row_Recordset11 = mysql_fetch_assoc($Recordset11));