mergeCells & getStyle->applyFromArray

Topics: User Forum
Aug 14, 2008 at 4:13 PM
So I am merging some cells and trying to figure out how to add borders on the merged cells. When I try to apply the borders using the style array I get the borders on only the first cell of the merged cells. Anyone got any clues?

- Tim
Developer
Aug 15, 2008 at 9:01 PM
The following method seems to be working. You can make use of the duplicateStyleArray method for the worksheet object:

$PHPExcel = new PHPExcel();
$worksheet = $PHPExcel->getActiveSheet();
$worksheet->mergeCells('B2:G9');

$style = array(
    'borders' => array(
        'top' => array(
            'style' => PHPExcel_Style_Border::BORDER_THICK,
        ),
        'left' => array(
            'style' => PHPExcel_Style_Border::BORDER_THICK,
        ),
        'right' => array(
            'style' => PHPExcel_Style_Border::BORDER_THICK,
        ),
        'bottom' => array(
            'style' => PHPExcel_Style_Border::BORDER_THICK,
        ),
    ),
    'fill' => array(
        'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
        'startcolor' => array(
            'rgb' => 'FFDD00',
        ),
        'endcolor' => array(
            'rgb' => 'FFDD00',
        )
    ),
);

$worksheet->duplicateStyleArray($style, 'B2:G9');