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

Regression in phpspreadsheet 1.28.0 in comparison to 1.24.1: Euro currency format doesn't work right anymore #3577

Closed
finn-matti opened this issue May 19, 2023 · 5 comments

Comments

@finn-matti
Copy link

finn-matti commented May 19, 2023

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?

(See the example project below)

The created file should handle numbers formatted as currencies correctly:

Screenshot 2023-05-19 at 18 08 52

What is the current behavior?

It doesn't display them correctly (at least) in Microsoft Excel for Mac 16.16.27:

Screenshot 2023-05-19 at 18 11 28

What are the steps to reproduce?

See: https://github.com/finn-matti/phpspreadsheet-problem for a minimal project.

What features do you think are causing the issue

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

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

I have only tested it with xlsx.

Which versions of PhpSpreadsheet and PHP are affected?

1.28.0 and 1.24.1. I have not tested any other versions.

@finn-matti finn-matti changed the title Regression in phpspreadsheet 1.28.0 in comparison to 1.24.1 Regression in phpspreadsheet 1.28.0 in comparison to 1.24.1: Euro currency format doesn't work right anymore May 19, 2023
@oleibman
Copy link
Collaborator

Your problem appears to have been caused by PR #3377, which changed the definition for the class constant you are using from a style with decimal positions to a style without decimal positions. If you know you will run only on 1.28 or later, you can use NumberFormat::FORMAT_CURRENCY_EUR to achieve the result you want. If you need your code to run on earlier versions as well, you can either hard-code the desired style, or you can use the following really ugly workaround:

    $numberFormat = defined(NumberFormat::class . '::FORMAT_CURRENCY_EUR_INTEGER')
        ? NumberFormat::FORMAT_CURRENCY_EUR
        : NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE;
    $this->worksheet->getStyleByColumnAndRow(1, 1)
                    ->getNumberFormat()
                    ->setFormatCode($numberFormat);

@finn-matti
Copy link
Author

@oleibman That's right. That shouldn't have happened. Nothing we can do about it now.

@oleibman
Copy link
Collaborator

Agree that it's unfortunate, and that previous behavior can no longer be restored. Closing ticket.

@mjomble
Copy link

mjomble commented Nov 13, 2023

We still have the option of clearly marking it as an accidental breaking change in the changelog / release notes, etc.

I just ran into the same issue and came here to figure out how I missed a breaking change, but saw the change still marked as a simple deprecation in the changelog.

@oleibman
Copy link
Collaborator

I have updated the change log with PR #3787 which I have just merged.

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

No branches or pull requests

3 participants