根据列值在Excel文件中查找行,并使用ClosedXML更新行值

时间:2018-05-17 11:17:22

标签: closedxml

我有一个excel文件,如下所示。我想在Excel中使用列值(如SubmissionID == 2)找到一行,然后更新特定行的电子邮件地址

Excel File

using (XLWorkbook wb = new XLWorkbook(filestream))
{
     var ws = wb.Worksheet(1);
     var range = ws.RangeUsed();
     var lastRow = range.LastRowUsed().RowNumber();

    // not able to find the column
     using (var rows = ws.RowsUsed(r => r.FirstCell().GetString() == "SubmissionID"))
     {
          foreach (var row in rows)
          {
                        // Do something with the row...
          }
      }

}

1 个答案:

答案 0 :(得分:1)

我认为你应该使用

using (var rows = ws.RowsUsed(r => r.FirstCell().GetString() == "2"))

using (var rows = ws.RowsUsed(r => r.FirstCell().Value == 2))