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

Uncorrect formula update on SUM when deleting row #2196

Open
asterd opened this issue Jun 29, 2021 · 1 comment
Open

Uncorrect formula update on SUM when deleting row #2196

asterd opened this issue Jun 29, 2021 · 1 comment

Comments

@asterd
Copy link

asterd commented Jun 29, 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?

When deleting a row (single or multiple), "SUM" formula doesn't update correctly if remains only one row.

What is the current behavior?

For example: I have a row with a SUM formula of type SUM(C6:C11).
Now, I need to delete rows between C7 and C11 included. I expect the SUM formula updated to SUM(C6) or SUM(C6:C6). But in this case, the formula update to SUM(C6:C7) that raise a recursive formula error

What are the steps to reproduce?

<?php

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

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$spreadsheet->getActiveSheet()->removeRow(6, 4);

Which versions of PhpSpreadsheet and PHP are affected?

latest

Possible solution:

I've do some tests on my pc, and I ended up that, in case of row deletion, the calculation does with insertRowBefore with a new row of type A . row rowsToDelete is not working correctly.
Maybe, a way to solve this is to do that:

ReferenceHelper.php

 .... 

$newCoordinate = Coordinate::stringFromColumnIndex($cellIndex   $pNumCols) . ($cell->getRow()   $pNumRows);
$pBeforeDelete = $pBefore;
if ($pNumRows < 0) {
     $pBeforeDelete = 'A' . ($beforeRow   $pNumRows);
}
....
           

and then use, in the method, $pBeforeDelete instead of $pBefore when calling updateFormulaReferences

@MarkBaker
Copy link
Member

There's a PR #2096 currently for this; but without unit tests, it needs a lot of additional work to verify that it does what it's supposed to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants