PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

Create method for deleting empty trailing rows/columns

Open lkmorlan opened this issue 2 years ago • 1 comments
trafficstars

This is a feature request

Sometimes, spreadsheet files will come with a large number of trailing rows and/or columns that are completely empty (all values are NULL). It would be helpful if there was a method that deletes these. Delete any row or column that is the last in the table and is entirely filled with NULL. Repeat until there are none left.

lkmorlan avatar Sep 06 '23 13:09 lkmorlan

(This problem is described in the documentation: https://phpspreadsheet.readthedocs.io/en/stable/topics/Looping%20the%20Loop/#using-rangetoarray)

But many worksheets do have trailing empty rows (or columns); and it is quite common for an Excel spreadsheet to have only a few rows or columns of data, but for the spreadsheet itself to claim that the highest row is 1,048,576 or that the highest column is XFD.


As described in https://github.com/PHPOffice/PhpSpreadsheet/issues/3240#issuecomment-1346918643 it is possible to ignore the empty cells when loading the file by using setReadEmptyCells(false).

cweiske avatar Jul 22 '24 06:07 cweiske

Question seems answered. Closing.

oleibman avatar May 20 '25 00:05 oleibman

This could still be a useful feature to have. One could load a spreadsheet, then make some changes to it that would result in there being trailing empty cells.

lkmorlan avatar May 20 '25 13:05 lkmorlan

I have not seen this type of problem except in association with loading a spreadsheet. Tell me how you think it might happen otherwise.

oleibman avatar May 20 '25 14:05 oleibman

If changes are made to a spreadsheet after it has been loaded. If some cells are set to NULL, the method could trim those cells and preceding empty cells. It's not a big deal; ::setReadEmptyCells() does what I need.

lkmorlan avatar May 20 '25 14:05 lkmorlan