使用Epplus查找值

Gab*_*one 6 c# linq epplus

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

Linq Code

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

结果视图中出错:

   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()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

dbr*_*lon 13

@krillgar建议的那样,您应该重写linq语句以包含Value返回的可能性null.

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