Delete non-consecutive rows from a sheet using list of rows
Created originally on Bitbucket by Prasanth
Hi,
I am a beginner to openpyxl and was wondering if there is a way to remove a bunch of rows from a sheet, using non-consecutive list of rows.
For example,
I would like to remove rows [1,10, 20, 1000], in which case I would have to pass each row iteratively to the Sheet.delete_rows() method and this is an issue when the file is very large and I have a lot of rows to remove, as this deletes and shifts the entire sheet each time the method is called and it seems to be a very expensive operation.
Is there a way for me to pass a list of non-consecutive rows to the function as a parameter, and have these removed in one go without having to pass each row iteratively? – for example:
Sheet.delete_rows([1,10,29])
Thank you so much.