Skip to content
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

Image and gray disappear after IOFactory::createWriter and save #4248

Closed
kboumedal opened this issue Nov 28, 2024 · 5 comments · Fixed by #4250
Closed

Image and gray disappear after IOFactory::createWriter and save #4248

kboumedal opened this issue Nov 28, 2024 · 5 comments · Fixed by #4250

Comments

@kboumedal
Copy link

kboumedal commented Nov 28, 2024

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 current behavior?

Image and gray disappear after IOFactory::createWriter and save

What are the steps to reproduce?

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(
[Tool choix subventions  - GMS_simulateur_eau-déchets.xlsx](https://github.com/user-attachments/files/17946990/Tool.choix.subventions.-.GMS_simulateur_eau-dechets.xlsx)
);

$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');

$temporaryPathfile = rtrim(sys_get_temp_dir(), \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR.md5(uniqid().mt_rand());

$writer->save($temporaryPathfile);

### What features do you think are causing the issue

- [ ] Reader
- [x] Writer
- [ ] Styles
- [ ] Data Validations
- [ ] Formula Calculations
- [ ] Charts
- [ ] AutoFilter
- [ ] Form Elements

### Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 3.4, PHP8.3
@kboumedal kboumedal changed the title Image ans gray disappear after IOFactory::createWriter and save Image and gray disappear after IOFactory::createWriter and save Nov 28, 2024
@oleibman
Copy link
Collaborator

I have downloaded your spreadsheet, and used PhpSpreadsheet to load and save it to a new file. Except for one svg image (we do not handle svg), all the images and the gray backgrounds are present in the output file. What do you think is missing? It might help if you upload your output file so that I can see where it differs from mine.

@kboumedal
Copy link
Author

Here is the after/before comparison, you can see some gray is missing on the left pane
image

@oleibman
Copy link
Collaborator

Ah, yes, sorry I missed that. I will see what I can find.

@oleibman
Copy link
Collaborator

oleibman commented Nov 29, 2024

Looks like another simple problem that will be difficult to solve. Every fill style has a start color and an end color, which the constructor by default initializes to white and black. And what documentation there is always shows the Xml containing both a start and and end color. So, what's in your spreadsheet? Several fill styles with an end color and no start color. In the case of the "darkDown" pattern (and certainly other patterns), which is what the cells in question use, the start color is used as the color of the dots or stripes or whatever distinguishes this pattern from the other possibilities. When the start color is omitted, Excel uses an "automatic" color. In this case, the automatic color is black (I have no idea if this is always the case), but since we initialize the color to white, that's what is being used, and why you see a discrepancy between your input and output files. So I need to find a way to implement automatic colors in a manner which fixes your case without causing compatibility breaks for others. It could take a while.

If you truly need this fixed while I am working on a solution, you could iterate through all the styles, and change the start color for darkdown patterns from white to black. I can supply code to do this if you need it. Other changes might be needed.

@oleibman
Copy link
Collaborator

It appears that background color can also be omitted, and pattern type can be omitted in conditional styles.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Nov 30, 2024
Fix PHPOffice#4248. PhpSpreadsheet has used what appear to be default attributes and tags when they are missing from Fill patterns and colors. However, Excel handles their absence a little differently from what the "default" would require. PhpSpreadsheet is changed to omit the attributes and tags in question when missing. This change is mostly targeted towards Xlsx read and write, but minor changes for Xls and Html write are also included.

This seems like it could be a breaking change, but I don't think it is. One test (DefaultFillTest introduced by PR PHPOffice#2050) must change, but the change is internal - loading and then saving the spreadsheet used in that change will appear the same after this change as it did before. Other differences are very likely to be bug fixes rather than breaks.
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.

2 participants