douken7402 2016-09-19 17:26
浏览 67
已采纳

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

I'm using a multicell table with fpdf and I want to format the value of a cell with bold letters depending on a condition

Example:

$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条回答 默认 最新

  • dongtun1683 2016-09-19 17:36
    关注

    Just call SetFont with 'B' to get bold and without 'B' for regular before displaying text :

    $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>
    

    Another approach :

    $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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?