Skip to content

Removing rows or columns that include range edges #1449

Closed
@jabouillei

Description

@jabouillei

This is a bug report. I have a fix for PHPExcel and confirmed that the fix is not present in PhpSpreadsheet.
PHPOffice/PHPExcel@1.8...jabouillei:patch-1

What is the expected behavior?

Removing rows or columns that overlap the edge of a range should adjust the edges of the range.
Also, formulas in column A should be adjusted even if only 5 columns are being removed starting with column G. (A formula in column A may refer to a range that includes column G.)

What is the current behavior?

The critical function for adjusting references only considers the case of adding rows or columns, not removing them. It also works if the removed rows or columns do not overlap the edge of the range.
There is also an uncommented "if" that "continue"s the loop that updates formulas in the initial columns of the sheet, so for example, formulas in column A do not get updated.

What are the steps to reproduce?

I provided a fix and have already put more time into this that I was supposed to, so I'm not providing a complete example, but here is what I've been using...

setIncludeCharts(true); $content = $objReader->load('/tmp/testremovecolumn.xlsx'); foreach ($content->getWorksheetIterator() as $worksheet) { //$worksheet->removeColumn('F',2); $worksheet->removeRow(3,3); } $objWriter = PHPExcel_IOFactory::createWriter($content, "Excel2007"); $objWriter->setPreCalculateFormulas(false); $objWriter->setIncludeCharts(true); $objWriter->save('/tmp/testremovecolumn2.xlsx'); ?>

That just requires a test file that has, for example, =SUM(C4:F7) in cell A1 and a bunch of numbers in the range C4:F7.

Which versions of PhpSpreadsheet and PHP are affected?

I'm using PHPExcel 1.8 on php 7.2.12 and php 5.6.16. I looked at the source code for PhpSpreadsheet master and see that neither problem has been addressed yet.
Someday, we'll get all our servers on php 7 and we'll probably move to PhpSpreadsheet. If the issue hasn't been addressed by then, I'll post a fix for PhpSpreadsheet master instead of just PHPExcel, but that might be a couple of years.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions