如何包含一个条件来检查列中的单元格值是否为空?

How to include a condition to check if cell value in column is empty?

如何添加条件来检查 excel 单元格列值以查看它是否为空?我已经使用 linq 映射映射了该列。当我去获取 excel 文件中是否为 null 的值时,我得到了 object not set to reference 错误。任何帮助表示赞赏。这是我得到的:

 public class Test
 {
 public string excelValue { get; set; }
 }

 string excel = @"C:\excel.xls";
 var excelFile = new ExcelQueryFactory(excel);
 excelFile.AddMapping<ExcelClass>(p => p.excelValue, "Name");
 var getvalue= excelFile.Worksheet<excelClass>("Sheet1").ToList();
 return getvalue;

public string GetMyName(List<excelClass> nameValue)
{
//NEED TO CHECK BEFORE SENDING TO A STRING VARIABLE!!!!!

string name = nameValue[1].excelValue.ToString();
return name;

}

您不能在空对象上调用方法,无论它是 ToString() 还是其他任何对象。

if(nameValue[1] != null)
{
   if(nameValue[1].excelValue != null)
   {
       return nameValue[1].excelValue.ToString();
   }
}