Skip to content

Instantly share code, notes, and snippets.

@sohail-aspose
Created December 24, 2020 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sohail-aspose/c87d1de331de3b6aa01eb0705aa81c96 to your computer and use it in GitHub Desktop.
Save sohail-aspose/c87d1de331de3b6aa01eb0705aa81c96 to your computer and use it in GitHub Desktop.
Delete the blank rows and columns
// Open an existing excel file.
Workbook wb = new Workbook("SampleInput.xlsx");
// Get the worksheets collection in the spreadsheet.
WorksheetCollection sheets = wb.Worksheets;
// Get first Worksheet from WorksheetCollection by index.
Worksheet sheet = sheets[0];
// This option will ensure the references (in formulas, charts)
// are updated while deleting blank rows and columns.
DeleteOptions options = new DeleteOptions();
options.UpdateReference = true;
// Delete the blank rows and columns.
sheet.Cells.DeleteBlankRows(options);
sheet.Cells.DeleteBlankColumns(options);
// Calculate formulas of workbook
wb.CalculateFormula();
// Save the excel file.
wb.Save("SampleOutput.xlsx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment