[英]Find row number based on text in excel using EPPLUS
I find some difficulty to fulfill my requirement in application. 我发现很难满足我的申请要求。 I use EpPlus
library in my application with c#
. 我在c#
应用程序中使用EpPlus
库。
I just need to find a text from excel sheet and its corresponding row number. 我只需要从Excel工作表及其对应的行号中查找文本。
IN my excel sheet I have a text "Total",
I want to find which row that text contains and need to get that row number. 在我的Excel工作表中,我有一个文本"Total",
我想查找文本包含的行并需要获取该行号。 Is it possible and not able to find in epplus
documentation. 是否有可能在epplus
文档中找不到。
Thanks & Regards Anil 谢谢与问候阿尼尔
Use can use LINQ query to get your result 使用可以使用LINQ查询来获取结果
int rowStart = worksheet.Dimension.Start.Row;
int rowEnd = worksheet.Dimension.End.Row;
string cellRange = rowStart.ToString() + ":" + rowEnd.ToString();
var searchCell =from cell in worksheet.Cells[cellRange] //you can define your own range of cells for lookup
where cell.Value.ToString() == "Total"
select cell.Start.Row;
int rowNum = searchCell.First();
You can get the cell address in which your string is. 您可以获取字符串所在的单元格地址。
foreach (var worksheetCell in worksheet.Cells)
{
if (worksheetCell.Value.ToString() == "Total")
{
var worksheetCellFullAddress = worksheetCell.Address;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.