Internally, openpyxl does not seem to have the concept of a โrowโ, it works with cells and tracks sizes, and if you use Worksheet.rows it computes a 2D array of cells from this. You can mutate an array, but it does not change the worksheet.
If you want to do this in a worksheet, you need to copy the values โโfrom the old position to the new position and set the value of the cells that are no longer needed for '' or None , and call Worksheet.garbage_collect() .
If your data set is small and has a uniform character (for example, all rows), you can better copy the corresponding cell (content) to a new worksheet, delete the old one and set the new one to the just deleted one.
The most elegant thing to do, IMHO, is to extend the Worksheet or subclass using the delete_rows method. I would implement such a method by changing the coordinates of its Cell in place. But this can be broken if the internal elements of openpyxl .
Anthon
source share