1

I have been using LinqToExcel Library Lately and i came across this issue.

here is the code

  var excel = new ExcelQueryFactory(fileName);
  var dataList = (from c in excel.WorksheetRangeNoHeader("A1", "A4", "Test Worksheet")
                select c).ToList();

This dataList Collection Will have something like "Cat","Dog" ,"Fish" and "Goat"

Now All i want to do is assign Fish to a variable as an string by doing something like this

string temp=dataList[2];

However when i run the code i get the value of temp as "LinqToExcel.RowNoHeader". Anyone got idea on how to extract the actual value Fish into the variable temp.

Thanks in Advance

Sike12
  • 1,232
  • 6
  • 28
  • 53
  • If you put a break point before `string temp=dataList[2];` can you tree the object out in the locals window to see what property is holding the value? – Bmo Jul 01 '14 at 10:39
  • There is no such properties. However in the debugger window i see something like this _items=LinqToExcel.RowNoHeader[4]; This is what holds the value – Sike12 Jul 01 '14 at 10:44

1 Answers1

1

Cracked it ! I was referring to the whole row rather than the first cell of each row. Therefore i needed C[0] in order to get the items.

 var excel = new ExcelQueryFactory(fileName);
 var dataList = (from c in excel.WorksheetRangeNoHeader("A1", "A4", "Test Worksheet")
            select c[0]).ToList();

And the extraction code will be

var temp=Convert.ToString(dataList[2]);
Sike12
  • 1,232
  • 6
  • 28
  • 53