-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
QuotePrefix Style being incorrectly applied when referencing a named cell in another sheet #3335
Comments
Agree that you have a problem. However, it is definitely in the Calculation engine, not the Reader. The following minor modification of your code demonstrates the problem without involving Reader: use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
$spreadsheet = new Spreadsheet;
$sheet1 = $spreadsheet->getActiveSheet();
$sheet1->setTitle('Sheet1');
$sheet2 = $spreadsheet->createSheet();
$sheet2->setTitle('Sheet2');
$sheet2->getCell('A1')->setValue('July 2019');
$sheet2->getStyle('A1')->setQuotePrefix(true);
$sheet2->getCell('A2')->setValue(3);
$spreadsheet->addNamedRange(new NamedRange('FM', $sheet2, '$A$2'));
$sheet1->getCell('A1')->setValue('=(A2+FM)');
$sheet1->getCell('A2')->setValue(38.42);
$array = $sheet1->toArray( null, true, false, false );
var_dump($array); Commenting out the quotePrefix statement results in the expected array. |
When it fails, the evaluation log is:
I believe that this only applies of the quote-prefixed cell is If I modify Owen's code to use cell B1 in sheet 2 instead of cell A1, then the evaluation works correctly
Evaluation of a defined name requires a cell reference to link it to the worksheet; and cell |
I believe it's actually an issue with the style for the first row. |
If the style for row 1 is quote-prefixed; then it will treat cell |
@MarkBaker absolutely. I'll try it out as soon as I see the PR. |
Wondering if this is the issue the folks in #950 were having. |
It's certainly possible that it's linked; though we never had any sample files for that issue to evaluate that problem, and no mention that I can see there in the Issue comments about Defined Name that would have helped narrow it down |
Just tried the code in the PR branch and it does appear to fix this issue in both my sample XLSX files and the more complex client file I was working on when I came across the issue. |
Thanks for that testing and confirmation I'll see about adding some unit tests and merging it to master once I've had some dinner |
This is:
What is the expected behavior?
A simple formula on
Sheet1
referencing a named cell onSheet2
should calculate properly. However, the Formula Engine produces a#VALUE
error if there is a quote prefixed value anywhere onSheet2
.Expected behaviour is that the formula should calculate properly.
What is the current behavior?
A
#VALUE
error is produced by the formula engine if there is a quote prefixed value anywhere onSheet2
.What are the steps to reproduce?
See attached Excel file for a minimal viable example spreadsheet.
Test.xlsx
Note that adding
To the above resolves the issue, however I need this to be set to
FALSE
.Oddly, if the cell containing the quoted value in the example XLSX is deleted, the issue persists until the entire row is deleted.
What features do you think are causing the issue
I think the root issue is a problem with the XLSX reader. I haven't fully debugged that code yet, but I suspect it is somewhere in the
if
block starting on line 596 ofphpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php
. Within thisif
block,quotePrefix
is set in two differentfor
loops. I suspect the issue exists in thosefor
loops, or in whatever code builds the$xfTags
and$cellXfTags
arrays. Perhaps they are being linked incorrectly.Commenting out the first
if
block in_calculateFormulaValue
inphpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php
also appears to fix the issue, which is why I believe thatquotePrefix
is being set incorrectly.My note above regarding the issue persisting until the entire row is deleted leads me to believe that the XLSX reader is incorrectly assigning cell styles in some cases, and that is leading to the
quotePrefix
attribute being incorrectly set.Does an issue affect all spreadsheet file formats? If not, which formats are affected?
I have only tried XLSX files.
Which versions of PhpSpreadsheet and PHP are affected?
PHP 7.4, PhpSpreadsheet 1.27
The text was updated successfully, but these errors were encountered: