ClosedXML find last row number

Daniel Blois picture Daniel Blois · Jan 31, 2017 · Viewed 17.1k times · Source

I'm using ClosedXML with C# to modify an Excel workbook. I need to find the last row number used but .RowCount() counts how many rows are in the worksheet. So it is returning 1 million rows when there are only a few thousand. I have tried LastRowUsed() but that doesn't return an int and there is no .row method for it. How can I get the last row in an int?

Answer

Raidri supports Monica picture Raidri supports Monica · Feb 1, 2017

The LastRowUsed() function returns a row object. Use

worksheet.LastRowUsed().RowNumber()

to get the number of the last row used.