Linq to excel mapping errors. RRS feed

  • Question

  • I want to be able to map a excel value whether it is empty or not. If i have a value, it works fine, but if i don't have a value in that cell, the error will be, object not set to reference... I'm using linq to excel.

    Here's my code so far:

    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)
        string name = nameValue[1].excelValue.ToString();
        return name;
    ^^^ //HERE IS WHERE I NEED IT TO OUTPUT "" INSTEAD OF (List`1 excelValue) 

    • Edited by vkid12 Thursday, June 25, 2015 7:12 PM
    Thursday, June 25, 2015 7:10 PM