1

I have a class that creates a PHPExcel document. Below are the styles I use. Hopefully they are fairly obvious from their names.

private $default_style = array(
    'font' => array(
        'name' => 'Verdana',
        'color' => array('rgb' => '000000'),
        'size' => 11
    ),
    'alignment' => array(
        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER
    ),
    'borders' => array(
        'allborders' => array(
            'style' => PHPExcel_Style_Border::BORDER_THIN,
            'color' => array('rgb' => 'AAAAAA')
        )
    )
);

private $title_style = array(
    'font' => array(
        'bold' => true
    ),
    'fill' => array(
        'type' => PHPExcel_Style_Fill::FILL_SOLID,
        'startcolor' => array('rgb' => '5CACEE')
    ),
    'alignment' => array(
        'wrap' => true
    ),
    'borders' => array(
        'allborders' => array(
            'style' => PHPExcel_Style_Border::BORDER_THIN,
            'color' => array('rgb' => 'AAAAAA')
        )
    )
);


private $new_swap_style = array(
    'font' => array(
        'bold' => true
    ),
    'fill' => array(
        'type' => PHPExcel_Style_Fill::FILL_SOLID,
        'startcolor' => array('rgb' => 'F9690E')
    ),
    'alignment' => array(
        'wrap' => true
    ),
    'borders' => array(
        'allborders' => array(
            'style' => PHPExcel_Style_Border::BORDER_THIN,
            'color' => array('rgb' => 'AAAAAA')
        )
    )
);

private $odd_row_style = array(
    'fill' => array(
        'type' => PHPExcel_Style_Fill::FILL_SOLID,
        'startcolor' => array('rgb' => 'CCCCCC')
    ),
    'borders' => array(
        'allborders' => array(
            'style' => PHPExcel_Style_Border::BORDER_THIN,
            'color' => array('rgb' => 'AAAAAA')
        )
    )
);

private $outline_border = array(
    'borders' => array(
        'outline' => array(
            'style' => PHPExcel_Style_Border::BORDER_THICK,
            'color' => array('rgb' => '676767')
        )
    )
);

private $right_border = array(
    'borders' => array(
        'right' => array(
            'style' => PHPExcel_Style_Border::BORDER_THICK,
            'color' => array('rgb' => '676767')
        )
    )
);

I apply the odd_row_style using this piece of code:

if ($key % 2 != 0) {
    $as->getStyle('A'.$row.':'.$last_col.$row)
       ->applyFromArray($this->odd_row_style);
}

Other than that, the only other styles I apply are the outline_border and right_border styles. They are applied at the end of the data I loop through like so:

// $row equals the last row after the data is looped through
$as->getStyle('D3:H'.($row))->applyFromArray($this->outline_border);
$as->getStyle('E3:E'.($row))->applyFromArray($this->right_border);

For some reason, the border in the default_style is getting overridden, but is applied again when I add the outline_border and right_border styles.

It is more obviously seen in the screenshot on rows 10 and 11. You can see that there is no border between them, so the gray rows mesh together. However, the border is applied properly under the "New" title in the same rows.

enter image description here

I tried adding the default_style again right before adding the outline_border and right_border styles with no luck.

Thanks in advance for any help!

UPDATE

I've realized that when I set the odd_row_style to a row, filling the cell colors overrides the borders, even though I have re-included the border default. It seems to do this whether or not the cell has a value. See cells F10:G11 (values), and A10:C11 (no values) in the picture above.

Even weirder, when I applied default_style to the whole sheet, the border colors were #c1c1c1 for everything, instead of #aaaaaa like I tried to set them.

This is driving me insane, if anyone can please help!

pnuts
  • 58,317
  • 11
  • 87
  • 139
Katrina
  • 1,922
  • 2
  • 24
  • 42

1 Answers1

0

For some reason, setting the border style using the ->getDefaultStyle()->applyFromArray() methods threw everything out of wack for me. If I set the cells explicitly using ->getStyle()->applyFromArray() by entering one or more cells, it works as expected. I'm not sure if this is the expected result or a bug, but I opened an issue on their github. Feel free to track it here.

Katrina
  • 1,922
  • 2
  • 24
  • 42