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.
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 };