Are you able to change the color of a cell in a .xlsx file with PHPspreadsheet? Couldn't find anything in their function list or on Stack Overflow.
Asked
Active
Viewed 3.2k times
14
-
1Perhaps you should read the [docs](https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/) particularly the section on styles – Mark Baker Feb 09 '18 at 19:32
-
Thank you, I should have looked more carefully. – jdwee Feb 09 '18 at 19:46
3 Answers
25
Tries to look this link Here
$spreadsheet->getActiveSheet()->getStyle('B2')
->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);

Natan Augusto
- 360
- 5
- 5
-
It is changing the Text color only. I want to change the Background of Cell – Irshad Khan Sep 18 '20 at 06:11
-
5
For those who understand "change cell color" as Background color and not Text color, the right code is:
$spreadsheet->getActiveSheet()->getStyle('[YOUR_CELL_OR_RANGE_HERE]')->getFill()
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
->getStartColor()->setARGB('YOUR_COLOR_CODE_HERE');
Example:
$spreadsheet->getActiveSheet()->getStyle('E2')->getFill()
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
->getStartColor()->setARGB('FFFF0000');

Mannyfatboy
- 389
- 7
- 14