[英]How can I iterate over a column to find cells with a specific value and then iterate over those rows?
我想搜索一列(A列)并找到所有“ Good”文件,然后我想在B列中创建所有数据的列表,其中“与文件有关的信息”与该列中的Good文件相对应A.因此,在最终列表中排除所有不良文件及其对应的信息
到目前为止,我的代码返回了A列中的所有Good项目,但返回了B列中的所有项目,而不仅仅是与A列相对应的项目。
Excel.Worksheet xlWorkSheet = (Excel.Worksheet)excelWorkbook.Sheets[sheetSpaces];
Excel.Range col = (Excel.Range)xlWorkSheet.Columns["A:A", Type.Missing];
Excel.Range colB = (Excel.Range)xlWorkSheet.Columns["B:B", Type.Missing];
foreach (Excel.Range item in col.Cells)
{
string text = (string)item.Text;
if (text == "Good")
{
Console.WriteLine(text);
foreach (Excel.Range itemSub in colB.Cells)
{
string textSub = (string)itemSub.Text;
}
}
}
}
您需要在循环中添加一个if语句:
if(item.Value().ToString().Contains("Good")){
// do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.