如何格式化多单元fpdf表中的单个单元格

时间:2016-09-19 17:26:03

标签: php cell fpdf

我正在使用带有fpdf的多单元表 我想根据条件使用粗体字母格式化单元格的值

示例:

$pdf->SetFont('Arial','B',10);
$pdf->Row(array("","IDUSER","NAME","AGE"); //header of the table<BR>
do {
    if($myrow["age"] >30)
         $age=<b>$myrow["age"]; //value in bold letter<br>
    else
        $age=$myrow["age"];

    $pdf->Row(array($n,$myrow["id_user"],$myrow["name"],$age));

} while ($myrow = mysql_fetch_array($result));

1 个答案:

答案 0 :(得分:1)

只需使用&#39; B&#39;拨打SetFont大胆而没有&#39; B&#39;在显示文字之前定期:

$pdf->SetFont('Arial','B',10);
$pdf->Row(array("","IDUSER","NAME","AGE"); //header of the table<BR>
do<br>
{<BR>
    if($myrow["age"] >30)<br>
      { $pdf->SetFont('Arial','B',10);  // ◄■■■■■■■■■■■■■ BOLD
        $age=$myrow["age"]; //value in bold letter<br>
      }
    else{ <br>
          $pdf->SetFont('Arial','',10);  // ◄■■■■■■■■■■■■■ REGULAR.
          $age=$myrow["age"];<br>
        } 
    $pdf->Row(array($n,$myrow["id_user"],$myrow["name"],$age));<br>

} while ($myrow = mysql_fetch_array($result);<br>

另一种方法:

$pdf->SetFont('Arial','B',10);
$pdf->Row(array("","IDUSER","NAME","AGE"); //header of the table<BR>
do<br>
{<BR>
    if($myrow["age"] >30)<br>
      { $font = "B"; // ◄■■■ BOLD FONT.
        $age=$myrow["age"]; //value in bold letter<br>
      }
    else{ <br>
          $font = ""; // ◄■■■ REGULAR FONT.
          $age=$myrow["age"];<br>
        } 
    $pdf->SetFont('Arial',$font,10); // ◄■■■ SET FONT.
    $pdf->Row(array($n,$myrow["id_user"],$myrow["name"],$age));<br>

} while ($myrow = mysql_fetch_array($result);<br>