Skip to content

Instantly share code, notes, and snippets.

@abc126
Created September 9, 2019 19:15
Show Gist options
  • Select an option

  • Save abc126/bf88829b84ae5b79ad84a6fbd64add3d to your computer and use it in GitHub Desktop.

Select an option

Save abc126/bf88829b84ae5b79ad84a6fbd64add3d to your computer and use it in GitHub Desktop.
TrimLastEmptyRows
worksheet.TrimLastEmptyRows();
public static void TrimLastEmptyRows(this ExcelWorksheet worksheet)
{
while (worksheet.IsLastRowEmpty())
worksheet.DeleteRow(worksheet.Dimension.End.Row);
}
public static bool IsLastRowEmpty(this ExcelWorksheet worksheet)
{
var empties = new List<bool>();
for (int i = 1; i <= worksheet.Dimension.End.Column; i++)
{
var rowEmpty = worksheet.Cells[worksheet.Dimension.End.Row, i].Value == null ? true : false;
empties.Add(rowEmpty);
}
return empties.All(e => e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment