Home » excel » c# – Counting cells in a column with EPPlus

c# – Counting cells in a column with EPPlus

Posted by: admin May 14, 2020 Leave a comment


I’m using EPPlus in a C# application for reading an Excel (.xlsx) file. What I need to do is counting how many cells in the column I contain the value Value.

For this I have defined the following query:

var query = (from worksheet.Cells["i:i"]
             where cell.Value.ToString().Equals("Value")
             select worksheet.Cells);

Howwever this does not seem to work. I’m pretty sure that the select statement is wrong but I don’t know what it should look like.

How to&Answers:

Cell.Text should work, assuming column I is the 9th column:

int count = worksheet.Cells[1, 9, worksheet.Dimension.End.Row, 9]
                     .Count(c => c.Text == "Value");

although it should also work with the address:

count = worksheet.Cells["i:i"].Count(c => c.Text == "Value");