Hi there,
I love this product and am trying to use it more and more in my day to day
I have an excel file which has loads of empty rows at the end which I need to delete
When i use the IXLRows.Delete or the IXLRow.Delete (when looping through the rows) i have a major performance issue when it attempts the Delete
The code used here is
var lastRow = ws.LastRowUsed().RowBelow();
var lastUnUsedRow = ws.LastRow();
//ws.Range(lastRow.RangeAddress.FirstAddress.ToString(), lastUnUsedRow.RangeAddress.LastAddress.ToString()).Delete(XLShiftDeletedCells.ShiftCellsUp);
IXLRows rows = ws.Rows();
foreach (IXLRow row in rows)
{
if (row.IsEmpty(true))
{
row.Delete();
var lastUnUsedCell = ws.RowsUsed().Count();
}
}
The above code, which is deleting only one row, has been running for a good 7 minutes now and not completed yet.
Is there a better way to do this?
I'm using version version 0.69.1.0 of the DLL
Thank you
Comments: Row deletes are slow (I need to work on it) but in your particular case you're checking all 1M+ rows in the worksheet to see if they're empty and deleting every single row that you're not using (probably most in the worksheet). Use something like: // Delete empty rows in the used range ws.RangeUsed().Rows(row => row.IsEmpty()).ForEach(row => row.Delete()); or // Delete the entire worksheet rows that are empty (within the range used) ws.RangeUsed().Rows(row => row.IsEmpty()).ForEach(row => row.WorksheetRow().Delete());
I love this product and am trying to use it more and more in my day to day
I have an excel file which has loads of empty rows at the end which I need to delete
When i use the IXLRows.Delete or the IXLRow.Delete (when looping through the rows) i have a major performance issue when it attempts the Delete
The code used here is
var lastRow = ws.LastRowUsed().RowBelow();
var lastUnUsedRow = ws.LastRow();
//ws.Range(lastRow.RangeAddress.FirstAddress.ToString(), lastUnUsedRow.RangeAddress.LastAddress.ToString()).Delete(XLShiftDeletedCells.ShiftCellsUp);
IXLRows rows = ws.Rows();
foreach (IXLRow row in rows)
{
if (row.IsEmpty(true))
{
row.Delete();
var lastUnUsedCell = ws.RowsUsed().Count();
}
}
The above code, which is deleting only one row, has been running for a good 7 minutes now and not completed yet.
Is there a better way to do this?
I'm using version version 0.69.1.0 of the DLL
Thank you
Comments: Row deletes are slow (I need to work on it) but in your particular case you're checking all 1M+ rows in the worksheet to see if they're empty and deleting every single row that you're not using (probably most in the worksheet). Use something like: // Delete empty rows in the used range ws.RangeUsed().Rows(row => row.IsEmpty()).ForEach(row => row.Delete()); or // Delete the entire worksheet rows that are empty (within the range used) ws.RangeUsed().Rows(row => row.IsEmpty()).ForEach(row => row.WorksheetRow().Delete());