【问题标题】:Table MultiCell in FPDFFPDF 中的表多单元格
【发布时间】:2014-10-14 17:07:18
【问题描述】:

我目前正在使用 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 个表格列并排放置。

【问题讨论】:

    标签: php fpdf


    【解决方案1】:

    您将需要手动设置单元格的位置(请参阅下面的更新方法)

    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();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-08
      • 1970-01-01
      • 2018-05-22
      相关资源
      最近更新 更多