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.
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
You can apply color to cells border while creating border.
Define style :
$border_style= array('borders' => array('right' => array('style' =>
PHPExcel_Style_Border::BORDER_THICK,'color' => array('argb' => '766f6e'),)));
Apply style :
$sheet = $objPHPExcel->getActiveSheet();
$sheet->getStyle("A2:A40")->applyFromArray($border_style);
Refer PhpExcel documentation here
Set border without applyFromArray()
can be done like this.
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getBorders()
->getBottom()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()
->getStyle('A1')
-> getBorders()
->getLeft()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getBorders()
->getRight()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getBorders()
->getBottom()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
The Border Style list are
BORDER_NONE - 'none'
BORDER_DASHDOT - 'dashDot'
BORDER_DASHDOTDOT - 'dashDotDot'
BORDER_DASHED - 'dashed'
BORDER_DOTTED - 'dotted'
BORDER_DOUBLE - 'double'
BORDER_HAIR - 'hair'
BORDER_MEDIUM - 'medium'
BORDER_MEDIUMDASHDOT - 'mediumDashDot'
BORDER_MEDIUMDASHDOTDOT - 'mediumDashDotDot'
BORDER_MEDIUMDASHED - 'mediumDashed'
BORDER_SLANTDASHDOT - 'slantDashDot'
BORDER_THICK - 'thick'
BORDER_THIN - 'thin'
For more PHPExcel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With