Search code examples
c#.net-corenpoi

How to get used range in .net core by using NPOI


I'm using NPOI in my .net core library to do some operations in my excel sheet.

I'm now want to get the used rang in the worksheet. Is there any way to achieve this target? For some reasons, I cannot use Microsoft.Office.Interop.Excel COM component.


Solution

  • I've solved this question by using the LastRowNum and LastCellNum property.

    For example, If I have got a ISheet instance like the following:

    var sheet = workbook.GetSheetAt(0);

    Then, I can get the range by the LastRowNum and LastCellNum property.

    var row = sheet.LastRowNum;
    var column = sheet.GetRow(row).LastCellNum;
    var range = new { row, column };