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

Number prefixed with dollar sign is replaced when using rangeToArray #4242

Open
1 of 8 tasks
sirbaconjr opened this issue Nov 25, 2024 · 3 comments · May be fixed by #4243
Open
1 of 8 tasks

Number prefixed with dollar sign is replaced when using rangeToArray #4242

sirbaconjr opened this issue Nov 25, 2024 · 3 comments · May be fixed by #4243

Comments

@sirbaconjr
Copy link

sirbaconjr commented Nov 25, 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 expected behavior?

A cell that contains value like 200 number, $200 value that is formatted as Text should be recognized as 200 number - $200 value when using the rangeToArray function.

What is the current behavior?

The cell is being recognized as 200 number - 0 value.

What are the steps to reproduce?

<?php

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

$inputFileName = __DIR__ . '/../issue.dollar.sign.xlsx';
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
$sheet = $spreadsheet->getActiveSheet();

print_r($sheet->toArray());

issue.dollar.sign.xlsx

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

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

XLS isn't affected.
XLSX is affected.

Which versions of PhpSpreadsheet and PHP are affected?

It seems all of them.

@sirbaconjr
Copy link
Author

I'm working on a PR to fix the above issue.

I already replicated the issue on the tests, now just need to finish writing the fix for it.

Any tips would be welcome, even more if this issue was noticed before by someone else. I couldn't find any previous issues or pull requests that would relate to this.

@sirbaconjr
Copy link
Author

I managed to isolate the issue up until this place:

https://github.com/PHPOffice/PhpSpreadsheet/blob/master/src/PhpSpreadsheet/Worksheet/Worksheet.php#L2832-L2840

If we don't format the data, the issue doesn't happen.

The replacement is happening on these lines:

https://github.com/PHPOffice/PhpSpreadsheet/blob/master/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php#L128-L130

It seems that even though the column is text is being considered a number formatter and then something recognizes the dollar signs followed by numbers as a regex replacement variable

@sirbaconjr
Copy link
Author

A solution is available on PR #4243

@oleibman oleibman linked a pull request Nov 25, 2024 that will close this issue
11 tasks
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.

1 participant