简体   繁体   中英

Counting cells in a column with EPPlus

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.

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM