ClosedXML查找最后一行的编号

我在C#中使用ClosedXML来修改Excel工作簿。 我需要find最后一个行号,但.RowCount()计算工作表中有多less行。 所以当只有几千条的时候它会返回100万行。 我试过LastRowUsed()但不返回一个int,并没有.row方法。 我怎样才能得到一个int的最后一行?

你可以使用RowsUsed();

 var wb = new XLWorkbook(); var ws = wb.worksheets.add("data"); var totalRows = ws.RowsUsed().Count(); 

LastRowUsed()函数返回一个行对象。 使用

 worksheet.LastRowUsed().RowNumber() 

得到最后一行使用的编号。

你必须使用.LastRowUsed()

official GitHub repo更有用的东西:

 range.FirstCell() range.FirstCellUsed() range.FirstColumn() range.FirstColumnUsed() range.FirstRow() range.FirstRowUsed() range.LastCell() range.LastCellUsed() range.LastColumn() range.LastColumnUsed() range.LastRow() range.LastRowUsed()