PhpSpreadsheet
PhpSpreadsheet copied to clipboard
Create method for deleting empty trailing rows/columns
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.
(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).
Question seems answered. Closing.
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.
I have not seen this type of problem except in association with loading a spreadsheet. Tell me how you think it might happen otherwise.
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.