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

getFormattedValue method return 'GENERAL' value #2450

Closed
mathgr opened this issue Dec 16, 2021 · 1 comment · Fixed by #2451
Closed

getFormattedValue method return 'GENERAL' value #2450

mathgr opened this issue Dec 16, 2021 · 1 comment · Fixed by #2451

Comments

@mathgr
Copy link

mathgr commented Dec 16, 2021

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?

Calling PhpOffice\PhpSpreadsheet\Cell::getFormattedValue on a number cell must return the actual number value (but string typed).

What is the current behavior?

Calling PhpOffice\PhpSpreadsheet\Cell::getFormattedValue on a number cell return 'GENERAL' value.

What are the steps to reproduce?

With this file: persons.xlsx

and this code:

<?php

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

$sheet = PhpOffice\PhpSpreadsheet\IOFactory::load('persons.xlsx')->getActiveSheet();

$birthYears = [
   'C2' => $sheet->getCell('C2')->getFormattedValue(),
   'C3' => $sheet->getCell('C3')->getFormattedValue(),
   'C4' => $sheet->getCell('C4')->getFormattedValue(),
];

with the version 1.17.1, the result is:

[
   'C2' => '1932',
   'C3' => '1964',
   'C4' => '1988',
];

but with the version 1.18.0 and older, the result is :

[
   'C2' => 'GENERAL',
   'C3' => 'GENERAL',
   'C4' => 'GENERAL',
];

Which versions of PhpSpreadsheet and PHP are affected?

1.18.0 and older.

Thank you

@oleibman
Copy link
Collaborator

Thank you for providing the sample file. This seems very similar to issue #2239 which was fixed by PR #2242. The issue was reported, and therefore fixed, only for Xls. Apparently it needs to be dealt with for Xlsx as well. Working on it.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Dec 17, 2021
Fix PHPOffice#2450. Treat input style GENERAL as if it were expected upper/lowercase.
oleibman added a commit that referenced this issue Dec 18, 2021
* General Style Specified in Uppercase in Input Xlsx

Fix #2450. Treat input style GENERAL as if it were expected upper/lowercase.

* Declare Method as Static

Surprised neither Phpstan nor Scrutinizer flagged this.

* Remove Duplicated Statement

Don't know why Scrutinizer didn't flag this the first time.
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