public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->styleCells(
'B1:D1',
[
'borders' => [
'outline' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
'color' => ['argb' => 'EB2B02'],
],
],
'font' => array(
'name' => 'Calibri',
'size' => 15,
'bold' => true,
'color' => ['argb' => 'EB2B02'],
)
]
);
},
];
}
Expected behavior:
it should changed the font color
Actual behavior:
nothing is working
Any additional information, configuration or data that might be necessary to reproduce the issue.
nothing is working is a bit of a vague statement. Please be more specific in the future. It's extremely hard to give support to vague descriptions.
Make sure you have imported the AfterSheet namespace in the top or your class. Put a dd($event) in the callback to make sure it get's called at all.
nothing is working of above code, i need to fill color to the cell
yes i imported class fonts changed but color of cell not
Your code is not trying to change the cell background color. Please refer to the PhpSpreadsheet documentation.
@iSarahSajjad Please read the API docs before you rising the issue!
Your solution is there https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/#formatting-cells
```
$event->sheet->styleCells(
'C7:G7',
[
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
],
'font' => [
'name' => 'Century Gothic',
'size' => 11,
'bold' => true,
'color' => ['argb' => 'EB2B02'],
]
]
);
$event->sheet->getStyle('C7:G7')->getFill()
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
->getStartColor()->setARGB('FFFF0000');
```
@iSarahSajjad Please read the API docs before you rising the issue!
Your solution is there https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/#formatting-cells$event->sheet->styleCells( 'C7:G7', [ 'alignment' => [ 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, ], 'font' => [ 'name' => 'Century Gothic', 'size' => 11, 'bold' => true, 'color' => ['argb' => 'EB2B02'], ] ] ); $event->sheet->getStyle('C7:G7')->getFill() ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) ->getStartColor()->setARGB('FFFF0000');
what if i want it for just one cell ?
not 'C7:G7' but 'C7' only
As per documentation, you can do it by following:
$spreadsheet->getActiveSheet()->getStyle('B2')
->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
Please refer the docs here:
https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/#conditional-formatting-a-cell
Most helpful comment
@iSarahSajjad Please read the API docs before you rising the issue!
Your solution is there https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/#formatting-cells
```
$event->sheet->styleCells(
'C7:G7',
[
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
],
'font' => [
'name' => 'Century Gothic',
'size' => 11,
'bold' => true,
'color' => ['argb' => 'EB2B02'],
]
]
);
$event->sheet->getStyle('C7:G7')->getFill()
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
->getStartColor()->setARGB('FFFF0000');
```