将 table 中的最后一行加粗
Bold the last row in table
如何在 fpdf
中创建最后一行 Bold
?
这是我的代码
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() 行,然后检查当前处理的行是否是最后一行。
$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();
}
如何在 fpdf
中创建最后一行 Bold
?
这是我的代码
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() 行,然后检查当前处理的行是否是最后一行。
$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();
}