用 Epplus 寻找价值

Finding a value with Epplus

我正在尝试使用代码通过 Epplus 和 Linq 在工作表中查找特定值的地址。该值在 D (4) 列中,但可以在任何单元格中 但是,显示如下错误

Linq 代码

var query3 = (from cell in sheet.Cells["d:d"]
    where cell.Value.ToString().Equals("CRÉDITOS")
    select cell);

结果视图错误:

   at ExcelTests.Form1.<>c.<button1_Click>b__1_0(ExcelRangeBase cell)
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()

正如 @krillgar 所建议的,您应该重写 linq 语句以包含 Value 返回 null 的可能性。

var query3 = 
    from cell in sheet.Cells["d:d"]
    where cell.Value?.ToString() == "CRÉDITOS"
    select cell;