Alright so I'm trying to receive the last row of an Excel sheet. My code to do so looked like this
public static int FindLastRow(Worksheet sheet)
{
int lastRow;
try
{
lastRow = sheet.Cells.Find("*", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, Xcl.XlSearchOrder.xlByColumns, Xcl.XlSearchDirection.xlPrevious, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Row;
}
catch (Exception)
{
lastRow = 1;
}
return lastRow;
}
but it isn't working as needed because it's returning the wrong row. Basically it returns the row of the widest column instead of the row# of last row.
That means this one returns 7
and this one returns 10
as you can see it does not returns the last row but rather the widest. How do I return the last row of a worksheet in C#?