2017-11-22 10 views
0

Boldの最後の行はどのようにしてfpdfにできますか?太字表の最後の行

は、ここに私のコードです

foreach ($data as $row) { 
      $cnt = 0; 
       foreach ($row as $col) { 
        if($cnt < 1){ 
         $this->Cell(9,5,$col,1,0,'C'); 
        } elseif ($cnt < 2) { 
         $this->Cell(18,5,$col,1,0,'C'); 
        } else { 
         $this->Cell(18,5, $col, 1, 0,'R'); 
        } 
        $cnt++; 
       } 
       $this->Ln(); 
      } 
     } 

更新されたコード:最後の行に到達するまでの行を追加しました条件。

foreach ($data as $row) { 
      $cnt = 0; 
      if ($currentRow === $totalRows) { 
       $this->SetFont('Arial','B'); 
       foreach ($row as $col) { 
        if($cnt < 1){ 
         $this->Cell(9,5,$col,1,0,'C'); 
        } elseif ($cnt < 2) { 
         $this->Cell(18,5,$col,1,0,'C'); 
        } else { 
         $this->Cell(18,5, $col, 1, 0,'R'); 
        } 
        $cnt++; 
       } 

      } else { 
       $this->SetFont('Arial'); 
       foreach ($row as $col) { 
        if($cnt < 1){ 
         $this->Cell(9,5,$col,1,0,'C'); 
        } elseif ($cnt < 2) { 
         $this->Cell(18,5,$col,1,0,'C'); 
        } else { 
         $this->Cell(18,5, $col, 1, 0,'R'); 
        } 
        $cnt++; 
       } 
      } 
      $currentRow++; 
      $this->Ln(); 
     } 

上記のサンプルコードでは、私の目標は、現在処理された行が最後のものである場合だけで、あなたはその後、count()行と確認することができ、最後の行に太字

答えて

0

を作ることで、行と列を作成します。

$totalRows = count($data); 
$currentRow = 1; 
foreach ($data as $row) { 
    // (...) 
    if ($currentRow === $totalRows) { 
     // this is the last row 
    } 
    $currentRow++; 
} 

ここに作業コードがあります。

foreach ($data as $row) { 
       $cnt = 0; 
       if ($currentRow === $totalRows) { 
        $this->SetFont('Arial','B'); 
        foreach ($row as $col) { 
         if($cnt < 1){ 
          $this->Cell(9,5,$col,1,0,'C'); 
         } elseif ($cnt < 2) { 
          $this->Cell(18,5,$col,1,0,'C'); 
         } else { 
          $this->Cell(18,5, $col, 1, 0,'R'); 
         } 
         $cnt++; 
        } 

       } else { 
        $this->SetFont('Arial'); 
        foreach ($row as $col) { 
         if($cnt < 1){ 
          $this->Cell(9,5,$col,1,0,'C'); 
         } elseif ($cnt < 2) { 
          $this->Cell(18,5,$col,1,0,'C'); 
         } else { 
          $this->Cell(18,5, $col, 1, 0,'R'); 
         } 
         $cnt++; 
        } 
       } 
       $currentRow++; 
       $this->Ln(); 
      } 
+0

こんにちは!上記のコードを見てください。更新されたコードを作成しようとしましたが、最後の行は '太字 'になりませんでした –

+0

nevermid私はそれを修正しました –

関連する問題