Free Support Forum - aspose.com

Deleting emty rows

Hi,

How to delete all empty (null) rows on all worksheets(except first and second) of a workbook?

Thank you.

Hi,


Thanks for your query.

I think you may try to use Cells.deleteBlankRows() and Cells.deleteBlankColumns to remove the rows/columns which are blank irrespective if those rows/columns are formatted. See the sample code segment for your reference:
e.g
Sample code:

WorksheetCollection worksheets = workbook.getWorksheets();
//Get the third worksheet. Similarly you may easily loop through all the worksheets to remove the blank rows/cols in your favourite worksheets only.
Worksheet sheet = collection.get(2);
sheet.getCells().deleteBlankColumns();
sheet.getCells().deleteBlankRows();

Hope, this helps a bit.

Thank you.