2017-11-22 6 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 나는 그것을 고정 시켰습니다. –

관련 문제