user1536396
user1536396

Reputation: 499

PHPExcel white background

I am importing an Excel spreadsheet into a web page using the PHPExcel libraries:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save('php://output');

it works but it overrides my page background to white. Every other element on the page it's formatted correctly according to my CSS but not the background. Any idea?

Upvotes: 2

Views: 3706

Answers (2)

user1536396
user1536396

Reputation: 499

Mark Baker point me in the right direction to answer my own question, this is the reason why I marked his answer as the accepted one.

To fix my problem I have added the following lines:

$objWriter->generateStyles(false);
echo $objWriter->generateSheetData();

after:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');

Upvotes: 0

Mark Baker
Mark Baker

Reputation: 212402

The default background for an Excel cell is white, so you probably want to change that. I don't know where you're setting the page background in the first place, unless you've modified the HTML Writer to do so, or changed it in the Excel file (you don't indicate which); but try setting a default cell background for the worksheet:

$objPHPExcel->getDefaultStyle()->applyFromArray(
    array(
        'fill' => array(
            'type'  => PHPExcel_Style_Fill::FILL_SOLID,
            'color' => array('argb' => 'FFFFFF00')
        ),
    )
);

Upvotes: 3

Related Questions