c# - 用 Epplus 寻找值(value)

标签 c# linq epplus

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

链接代码

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

结果 View 中的错误:

   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()

enter image description here

最佳答案

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

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

关于c# - 用 Epplus 寻找值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42539689/

相关文章:

c# - 使用 Enumerable 和 Lambda 过滤文件列表并删除不需要的扩展名

c# - 在树状通用列表中按字母数字顺序排列子项的扩展方法

asp.net-mvc - 存储库模式 - MVC 店面

c# - 将表而不是范围定义为数据透视表 'cacheSource'

c# - 使用 ExcelDataReader 和 Epplus 访问 protected Excel 文件

c# - 尝试使用 Entity Framework 修复错误的数据库设计,特别是外键数据注释

c# - 在 Windows 应用商店应用程序中使用 Azure 表存储的最佳实践是什么?

c# - IIS 7.5 : unable to login 中的 MVC5 与 Windows 身份验证

Linq Union 不起作用

c# - 使用 EPPlus 库使用 C# 直接在 FTP 上创建 Excel 文件