PHPExcel set border color of a cell

Muntashir Akon picture Muntashir Akon · Jul 3, 2015 · Viewed 61.8k times · Source

How to set border color of a cell? I used this code, but it's not working:

$objPHPExcel->getActiveSheet()
                ->getStyle('A1')
                ->getBorders()
                ->getAllBorders()
                ->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN)
                ->getColor()
                ->setRGB('DDDDDD');

I know applyFromArray() works fine. But I don't want to use it.

Answer

Gjermund Dahl picture Gjermund Dahl · Feb 24, 2016

A bit late, but for the record, I found that this syntax worked fine;

$ActiveSheet->getStyle("A1:Z1")->applyFromArray(
    array(
        'borders' => array(
            'allborders' => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN,
                'color' => array('rgb' => 'DDDDDD')
            )
        )
    )
);

I also found a complete list of styles and attributes here: http://www.bainweb.com/2012/01/phpexcel-style-reference-complete-list.html