[英]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.