Skip to content

Opening an Excel file which reuses an image multiplies the image on save #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MAKS-dev opened this issue Jun 9, 2018 · 5 comments · Fixed by #2416
Closed

Opening an Excel file which reuses an image multiplies the image on save #543

MAKS-dev opened this issue Jun 9, 2018 · 5 comments · Fixed by #2416

Comments

@MAKS-dev
Copy link

MAKS-dev commented Jun 9, 2018

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)

What is the expected behavior?

When one imagefile is reused in the Excel document for e.g. 3 times, it is only placed once in the xlsx file (can be checked by opening it with WinRAR).
After opening the file with PhpSpreadsheet and saving it the image file must still be reused in the xlsx file and placed only once.
This prevents large Excel sheets containing multiple copies, of e.g. a company logo, for growing to a huge file.

What is the current behavior?

After opening the xlsx file with PhpSpreadsheet and saving it, even without any additional processing, there are multiple image files in the xlsx file. When the document had 3 references, PhpSpreadsheet will put 3 image files in the xlsx.

What are the steps to reproduce?

Start a new document with Excel 2016, insert a small PNG image, copy and paste the image a few times. Save the document.
Rename it to .rar and open it with WinRAR, browse to xl/media to see only one png file.
Rename back to .xlsx and upload to webserver.

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:

<?php

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

// Create new Spreadsheet object
$spreadsheet = IOFactory::load('test-in.xls');

// add code that show the issue here...
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('test-out.xlsx');

You'll notice that the new file has increased roughly 2x the image size.
A check with WinRAR shows 3 copies of the file.

Which versions of PhpSpreadsheet and PHP are affected?

Just downloaded the lastest version here.
PHP version 7.0.23

@pimpreneil
Copy link

I have just reproduced the problem. A workaround idea would be greatly appreciated 👍

@stale
Copy link

stale bot commented Aug 27, 2018

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.

@stale stale bot added the stale label Aug 27, 2018
@MAKS-dev
Copy link
Author

I'd really appreciate to keep this one open since it's still a bug.

@stale
Copy link

stale bot commented Oct 26, 2018

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.

@stale stale bot added the stale label Oct 26, 2018
@stale stale bot closed this as completed Nov 2, 2018
@MAKS-dev
Copy link
Author

MAKS-dev commented Sep 4, 2019

This is still an issue.
Recently updated to version 1.8.2 on PHP 7.1.25 and retested the above.
You can use the attached file as input: test-in.xlsx

Excel shows three times the same image and when checking the content (using unrar) there only one .png.
After opening and saving with PhpSpreadsheet, there are three .png files in the file.

When creating larger Excel reports based on a template containing multiple copies of a larger image, the PhpSpreadsheet generated file will grow very large.

Please let me know when more information is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants