Bleader Bleader
Bleader Bleader

Reputation: 61

Background color cell is always black with Excel 2007

When creating a Excel 5 file through PHPExcel, I am able to display the background color cell in any color but as soon as I switch to Excel 2007, the background color remains constantly black, is there any fix available to sort it out? Here's the subset of my code where the goal is to display the column header in yellow, any help would be appreciated, thanks in advance:

$styleArrayTableHeader = array(
                         'fill' => array(
                         'type' => PHPExcel_Style_Fill::FILL_SOLID,
                         'rotation' => 90,

                         'startcolor' => array(
                         'argb' => '#ffff00',    // yellow 
                          ),

                         'endcolor' => array(
                         'argb' => '#ffff00',
                         ),),);

$objPHPExcel->setActiveSheetIndex(0);
$worksheet = $objPHPExcel->getActiveSheet();
$worksheet->getStyle('B6:K6')->applyFromArray($styleArrayTableHeader);
.....
.....

Upvotes: 2

Views: 1723

Answers (2)

anydasa
anydasa

Reputation: 2623

you need check fill type of cell

if ( $pStyle->getFill()->getFillType() == PHPExcel_Style_Fill::FILL_NONE ) {
    $color = 'white'
} else {
    $color = '#' . $pStyle->getStartColor()->getRGB()
}

Upvotes: 1

Mark Baker
Mark Baker

Reputation: 212402

Can you retry with the latest develop branch code from github - there's at least one fix in there for the fill styling in Excel 2007...

Also you're using trying to set argb with rgb values. Either use argb values, or set rgb instead

Upvotes: 0

Related Questions