This article guides how to remove blank rows in Excel using C#. It has the details to set the development environment, a list of steps depicting the program flow, and a sample code to eliminate empty rows in Excel using C#. It will also assist in updating references on other worksheets after deleting the empty rows.
Steps to Delete Blank Lines in Excel using C#
- Set the environment to use Aspose.Cells for .NETto delete blank rows
- Load the target Excel file using the Workbook class having blank rows and columns in the data
- Access the target sheet from the sheet collection
- Access the cell collection from the sheet
- Call the DeleteBlankRows() method from the Cells class
- Save the output
These steps describe how to delete empty lines in Excel using C#. Commence the process by loading the source Excel file into the Workbook class object and accessing the target sheet from the collection of sheets in the workbook. Call the DeleteBlankRows() to delete empty rows with no data or other objects.
Code to Delete Blank Rows Excel using C#
This sample code demonstrates how to delete all blank rows in Excel using C#. You may call the DeleteBlankColumns() to delete all the blank columns with no data or other objects. You can pass the optional parameter DeleteOptions to these methods if you want to update references on other sheets while deleting rows and columns from the data.
This article has taught us how to eliminate blank rows in Excel using C#. To insert rows in a sheet, refer to the article on How to insert rows in Excel using C#.