How can I configure the first row of my Excel document as a header row?
I can only find ways to customize the style of the cells in the first row. For this I made myself a little helper method, but there must be a flag I can set, right?
What I'm currently using as a "workaround":
/**
* Applies the header style (bold font, and gray bg) to the given row in a sheet.
*
* @param Worksheet $sheet
* @param int $row
*
* @return Worksheet
*/
private function applyHeaderStyle(Worksheet $sheet, int $row = 1): Worksheet
{
$highestColumn = $sheet->getHighestColumn();
$sheet
->getStyle("A{$row}:{$highestColumn}{$row}")
->getFont()
->setBold(true);
$sheet
->getStyle("A{$row}:{$highestColumn}{$row}")
->getFill()
->setFillType(Fill::FILL_SOLID)
->getStartColor()
->setARGB('FFBEC0BF');
return $sheet;
}
But this will apply only styles and only to a limited set of cells and not the infinite length of the row.
Update:
Getting the style like ->getStyle("{$row}:{$row}")
and applying a bold font and background color to it, like proposed in this answer, works for the font style but not for the background color.
Apart from that, I still wonder if an Excel header is really "only" marked by its design, or if there is a flag for it.