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

[Bug]: Large numbers are cut of after x digits and displayed as scientic notation (even with text format) #4023

Closed
1 task done
frknakk opened this issue Oct 31, 2023 · 2 comments
Labels

Comments

@frknakk
Copy link

frknakk commented Oct 31, 2023

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.49

What version of Laravel are you using?

10.30.0

What version of PHP are you using?

8.2.3

Describe your issue

Large numbers starting at 12 digits get displayed as scientific notation (e.g. "1E+11"), even with column format "Text".
Large numbers starting at 16 digits get rounded to 15 digits, even with column format "Text".

Use case: I want to export serial numbers in a xlsx file that are often 16 digits. The last number gets rounded and therefore makes the serial number invalid. I couldn't find a workaround except adding a prefix like "A" before every number.

Possible solution: The column formats get applied after the rows are already inserted into excel (close function in Sheet.php), which converts the already broken number (scientific notation + rounded) into text. Instead, the column formats should be applied before the rows get inserted into excel (open function in Sheet.php), so that the number doesn't get rounded at all if the column format is "text".

How can the issue be reproduced?

Few examples that show the problem:

"10000000000000000" is displayed as "1E+16", but you can copy the correct number from the formula by clicking on the cell.
"10000000000000100" is displayed as "1E+16", but you can copy the correct number from the formula by clicking on the cell.
"10000000000000011" is displayed as "1E+16", but the formula field shows "10000000000000000".
"10000000000000001" is displayed as "1E+16", but the formula field shows "10000000000000000".
"10000000000000051" is displayed as "1E+16", but the formula field shows "10000000000000100".

What should be the expected behaviour?

Display the large numbers as they are if the column format is "text".

@frknakk frknakk added the bug label Oct 31, 2023
@patrickbrouwers
Copy link
Member

patrickbrouwers commented Nov 1, 2023

See PHPOffice/PhpSpreadsheet#168

You want to use a value binder to mark that column as string data type instead of it autodetecting it as a number. https://docs.laravel-excel.com/3.1/exports/column-formatting.html#value-binders

@frknakk
Copy link
Author

frknakk commented Nov 1, 2023

Thanks! that worked.

@frknakk frknakk closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants