PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.36k stars 3.47k forks source link

Missing header image when opening an excel file an saving it #1645

Closed Raemy92 closed 1 year ago

Raemy92 commented 4 years ago

This is:

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

I'm using this library on a TYPO3 installation to create excel order sheets from some articles. Everything works like a charm but the image in the header disappears.

I'm using a tamplate .xlsx file with the headers (image and some text) included, insert the articles with this library and save it to another path.

When I'm opening the file the header text and the articles are correctly saved but no the header image.

What is the expected behavior?

The same header as in the template file (image and text)

What is the current behavior?

Only the header text appears. The image on the header left is missing.

What are the steps to reproduce?

  1. Load the Excel template

    $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($this->pathToTemplate);
  2. Make some changes (in my case add the articles). I used a loop with something similar to this:

    $spreadsheet->getActiveSheet()->setCellValue($cell, $text);
  3. Save the File in another path because the template is used multiple times

    $writer = new Xlsx($spreadsheet);
    $writer->save($savePath);

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

See code above.

I also tried to insert the image manually:

$drawing = new HeaderFooterDrawing();
$drawing->setName('Logo');
$drawing->setPath($pathToImage);
$drawing->setHeight(90);
$spreadsheet->getActiveSheet()->getHeaderFooter()->addImage($drawing, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT);

Which versions of PhpSpreadsheet and PHP are affected?

PHPSpreadSheet: 1.14 PHP: 7.2

k7y6t5 commented 4 years ago

@Raemy92 I haven't tried working with a template that already contains a header image but I have tried to insert one manually. It's not working for me either.

https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/#setting-the-print-header-and-footer-of-a-worksheet

PHPSpreadsheet 1.8 PHP 7.4.9

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.

oleibman commented 1 year ago

Closing. I believe this issue is resolved. For example, if I load tests/data/Reader/XLSX/issue.3126.xlsx and save it elsewhere, the output file contains the same footer image as the input file. The same is true when I add a header image as well.