2016-11-23 32 views
2

FPDFとCellメソッドを使用してテーブルを作成しました。これは素晴らしい結果でしたが、各列の幅が設定されていたため、テーブルが右ページの余白を超え、製品名が製品価格と重なり、読みにくくなったためいくつかの問題が発生しました。FPDF MultiCellで列ごとに1行を作成する

GoogleとStackの問題を調査した後、私はコードをMultiCellに変更しましたが、各列には行全体が追加されました。私はCellとMultiCellテーブルの図を提供しており、各メソッドのコードも提供しています。

あなたのお役に立てれば幸いです。

ありがとうございました。マルチセル方法について

class PDF extends FPDF {  
    function LoadData($file) { 
     $lines = file($file); 
     $data = array(); 
     foreach($lines as $line) 
     $data[] = explode(';', trim($line)); 
     return $data; 
    } 

    function BasicTable($header, $data) { 
     $nameIndex = array_search ('Name', $header);  

     foreach($header as $key => $col) { 
      $width = ($key == $nameIndex) ? 80 : 40; 
      $this->Cell($width, 7, $col, 1);    
     } 

     $this->Ln(); 

     foreach($data as $row) { 
      foreach($row as $key => $col) { 
       $width = ($key == $nameIndex) ? 80 : 40; 
       $this->Cell($width, 6, $col, 1); 
      } 

      $this->Ln(); 
     } 
    } 
} 

コード:

マルチセル: enter image description here

セル: enter image description here

コードセル方式のため

class PDF extends FPDF {  
    function LoadData($file) { 
     $lines = file($file); 
     $data = array(); 
     foreach($lines as $line) 
     $data[] = explode(';', trim($line)); 
     return $data; 
    } 

    function BasicTable($header, $data) { 
     $nameIndex = array_search ('Name', $header);  

     foreach($header as $key => $col) { 
      $this->MultiCell($width, 7, $col, 1);    
     } 

     $this->Ln(); 

     foreach($data as $row) { 
      foreach($row as $key => $col) { 
       $this->MultiCell($width, 6, $col, 1); 
      } 

      $this->Ln(); 
     } 
    } 
} 

答えて

関連する問題