【发布时间】:2019-09-05 14:20:10
【问题描述】:
我需要为行设置浅灰色背景色。我对我的 PDF 使用多单元格视图。 我的代码是:
$countRow = 0;
foreach ($arrPeriod as $key=>$val) {
if($countRow % 2 == 0){
$this->setFillColor(230,230,230);
$this->SetTextColor(0,0,0);
}else{
$this->setFillColor(255,255,255);
$this->SetTextColor(0,0,0);
}
$this->Row([
$val['lead_name'],
$val['content'],
$val['date_due']
]
);
$countRow++;
}
我有一个问题,不是完整的列有浅灰色背景:
我的行函数是:
function Row($data)
{
//Calculate the height of the row
$nb = 0;
for ($i = 0; $i < count($data); $i++) {
$nb = max($nb,$this->GetMultiCellHeight($this->widths[$i], $data[$i]));
}
$h = 5 * $nb;
//Issue a page break first if needed
$this->CheckPageBreak($h);
//Draw the cells of the row
for ($i = 0; $i < count($data); $i++) {
$w = $this->widths[$i];
$a = isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
//Save the current position
$x = $this->GetX();
$y = $this->GetY();
//Draw the border
$this->Rect($x, $y, $w, $h);
//Set font
if ($i == 0 || $i == 2) {
$this->SetFont('Arial', 'B', 10);
} else {
$this->SetFont('Arial', '', 10);
}
//Print the text
$this->MultiCell($w, 4.5, $data[$i], 0, $a, true);
//Put the position to the right of the cell
$this->SetXY($x + $w, $y);
}
//Go to the next line
$this->Ln($h);
}
我怎样才能修复它并正确填写我的行?
【问题讨论】:
-
将标志传递给您的
row函数以指示您是否想要灰色背景。现在,您正在设置已知单元格大小之前的颜色。调整单元格大小后,在函数中设置文本和填充颜色。