问题
Is it possible to get a cell value from excel sheet using EPPlus and Linq? Example:
I have an excel sheet with 3 columns
Column 1 = Userid
Column 2 = Email address
Column 3 = Full name
Now i would like to return the email address where userid = x
I hope it's more clear now.
回答1:
Suppose Column 1
is a
, Column 2
is b
:
var sheet = excelPackage.Workbook.Worksheets[sheetname_orSheetIndex];
var objs = from cell in sheet.Cells["a:a"] // a:a is the column a, Userid
where cell.Value.ToString().Equals(x) // x is the input userid
select sheet.Cells[cell.Start.Row, 2]; // 2 is column b, Email Address
It will work! Edited: It will return the collection of ExcelRange.
回答2:
Not being exactly sure what you are trying to do, here is an example of getting the value from a cell:
excelPackage.Workbook.Worksheets
.FirstOrDefault(w => w.Name == "Your Worksheet Name")
.Cells.FirstOrDefault(c => c.Address == "Your Cell Address").Value;
Just make sure you are using the System.Linq namespace
来源:https://stackoverflow.com/questions/13857559/get-a-cell-value-from-excel-using-epplus-and-linq