-
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
SYLK shared formulae #2267
Comments
Excellent documentation - thanks. However, a little more investigation is needed. The result of getValue on cell A2 should not be 2; it should be the formula |
PHPSpreadsheet already implemented the shared formula logic for XLSX (https://github.com/PHPOffice/PhpSpreadsheet/blob/master/src/PhpSpreadsheet/Reader/Xlsx.php#L320 is the relevant part) and in XLS. To handle the shared formula case: track whether the "S" field is present and separately store the R and C values. If "S" is found, use the R and C values to find the base cell, grab the formula, then shift to the current address. In our example If the RC-formula is stored ( If the A1-formula is stored ( |
Fix PHPOffice#2267. The Slk format has a way to express a "shared formula", but the Slk reader does not yet understand it. Thanks to @SheetJSDev for documenting the problem and pointing the way towards a solution. It has taken a long time to get there. Part of the problem is that I have not been successful in getting Excel to use this type of construction when saving a Slk file. So I have resorted to saving a Slk file where shared formulas *could* be used, and then editing it by hand to actually use them. It would not surprise me in the least to have neglected one or more possible ways to specify a shared formula; but, at least the issue as documented is resolved, and if new issues arise, we'll probably be in better shape to deal with them.
* Slk Shared Formulas Fix #2267. The Slk format has a way to express a "shared formula", but the Slk reader does not yet understand it. Thanks to @SheetJSDev for documenting the problem and pointing the way towards a solution. It has taken a long time to get there. Part of the problem is that I have not been successful in getting Excel to use this type of construction when saving a Slk file. So I have resorted to saving a Slk file where shared formulas *could* be used, and then editing it by hand to actually use them. It would not surprise me in the least to have neglected one or more possible ways to specify a shared formula; but, at least the issue as documented is resolved, and if new issues arise, we'll probably be in better shape to deal with them. * Update CHANGELOG.md
This is:
This SYLK file uses the shared formula optimization that is present in XLS and XLSX:
Excel understands this as a worksheet with A1 set to 1, A2 set to A1+1 (cached value 2), A3 set to A2+1 (cached value 3)
PHPSpreadsheet incorrectly handles the A3 line, setting A2 to 3, because of an error in Slk.php:
The code appears to assume that
C
andR
refer to the cell but it in fact refers to the referenced cell. It will attempt to set A2 to the value 3.Unfortunately there's no official spec for any of this, but it appears that the
C
record supports the following fields:S
: signals that the cell is using a shared formulaR
andC
: row/column of the cell with the formula (1-indexed numeric values)What is the expected behavior?
print_r($sheet->getCell("A2")->getValue());
should print 2What is the current behavior?
print_r($sheet->getCell("A2")->getValue());
prints 3What are the steps to reproduce?
Save the SYLK codeblock to
test.slk
and runWhich versions of PhpSpreadsheet and PHP are affected?
All versions of PHPSpreadsheet (error inherited from PHPExcel) and every commit of PHPExcel on github (blamelog points to PHPOffice/PHPExcel@509f27e )
The text was updated successfully, but these errors were encountered: