Created
September 9, 2019 19:15
-
-
Save abc126/bf88829b84ae5b79ad84a6fbd64add3d to your computer and use it in GitHub Desktop.
TrimLastEmptyRows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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