How to get the Row count for only Specified Range of columns in WorkSheet using ClosedXMl

2.9k views Asked by At

I have a worksheet and one column of work sheet has more number of rows and remaining columns has different number of rows. I had a requirement like need to get the rowcount of those columns only not the irrelevant column. I had used the below code to get the rowcount but it is Counting by adding the rows in columns with the rows in irrelevant column.

For Example if I use the below code for the For the worksheet shown in image I am getting 6 but I need to get the 3.

int RowCount = workSheet.Rows().Count();

See the below image:

enter image description here

1

There are 1 answers

0
jose On BEST ANSWER

To get the Count of Specified Rows we Can use the below code

int RowCount = workSheet.Range("A2:k2").RowsUsed().Count();