Skip to content

Setting header image on only first page #484

@alistairreynolds

Description

@alistairreynolds

This is:

- [x] a bug report
- [ ] a feature request
- [x] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Header should be able to have an image on the first page, then text on others.

What is the current behavior?

If the worksheet is set with the header to be different on the first page with setDifferentFirst(true) and a the image put into the firstHeader, it will not display the image and leave that space blank. However if setDifferentFirst is set to false, or if the image is set to load in every header, it will display.

This occurs when opening on Excel in Office365 on MacOS

What are the steps to reproduce?

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// add code that show the issue here...
// Needs an image available

$headerImage = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing();
$headerImage->setName('Header Logo');
$headerImage->setPath('images/logo.png');
$headerImage->setHeight(24);

$worksheet = $spreadsheet->getActiveSheet();
$worksheet->getHeaderFooter()->addImage($headerImage, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_CENTER);
$worksheet->getHeaderFooter()->setDifferentFirst(true);
$worksheet->getHeaderFooter()->setFirstHeader("&C&G&R&D");
$worksheet->getHeaderFooter()->setOddHeader("&R&D");

$currentRow = 1;
$results    = [
    [
        'First Name',
        'Last Name',
    ],
];
for ($i = 0; $i < 100; $i ++) {
    $results[] = ["Bill", "Smith"];
}
foreach ($results as $result) {
    $currentColumn = "A";
    foreach ($result as $r) {
        $cell = $worksheet->getCell($currentColumn . $currentRow);
        $cell->setValue($r);
        $currentColumn ++;
    }
    $currentRow ++;
}

$filePath  = "app/temp/test.xlsx";
$objWriter = new Xlsx($spreadsheet);
$objWriter->save($filePath);

return $filePath;

Which versions of PhpSpreadsheet and PHP are affected?

1.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions