Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

Commented Unassigned: ClosedXML IXLRow.Delete() very slow [9317]

$
0
0
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: Hi, Thanks for your reply. I tried both samples you provided, and unforunately neither of them work. I have 700+ empty rows at the end of my worksheet that I'm trying to delete and after the delete lines run, those lines are still there. I have also tried to set IncludeFormats to true in case that was stopping it but again that didn't help either ws.RangeUsed().Rows(row => row.IsEmpty(true)).ForEach(row => row.Delete()); //or // Delete the entire worksheet rows that are empty (within the range used) //ws.RangeUsed().Rows(row => row.IsEmpty(true)).ForEach(row => row.WorksheetRow().Delete());

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>