PHPExcel is a library written to aid in the development of PHP applications for reading and writing spreadsheet files – particularly Excel. At the very least, that’s what I know since PHPExcel as stated in its archived repository, is already DEAD. It is now succeeded by a new library which is the PhpSpreadsheet.
So for this info, I would just like to show you how to fill the background color of a cell in Excel using a code snippet which was fairly shared on Stackoverflow.
function cellColor($objPHPExcel, $cells, $color){
$objPHPExcel->getActiveSheet()->getStyle($cells)->getFill()->applyFromArray(array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array(
'rgb' => $color
)
));
}
Since I am using this inside a PHP Framework, this is just a bit different from the original answer provided on the link above but its entirety is a mimic of it.
With this function, the developer will just have to call the function and supply the library instance, targeted cells and colors in hexadecimal format as parameters to have it working.
This could be used simply as such:
cellColor($objPHPExcel, 'A17:I17', 'F28A8C');
By doing so, this will produce the following output.
Surely you’d have everything set by now. If you have any questions, please don’t hesitate to drop your comments down below.
Discussion about this post