1

I am trying to pull an entire row of values off of an excel file using linq to excel. I have all of the column names (there's 104 different ones) and now I just need to get the one row of values associated with each header. What I would like to do is just pull the entire second row of values, but I haven't been able to figure a work around for that.

Does anyone know of a way to just pull one row? Or do I need to approach this differently and pull the individual value by the header name.

Thank you.

Rob Jarvis
  • 356
  • 1
  • 4
  • 13
  • 1
    You would like to pull only the first row after the header? If you have an object `Company` that has 104 properties mapping to the headers, you should be able to do something like `var firstCompany = excel.Worksheet().First();`. – Alden Feb 10 '14 at 18:23
  • @Alden Yes I just wanted to pull the first row after the header. I avoided making the object since I did not want to hard code out 104 different vals; but my understanding of mapping may be wrong. – Rob Jarvis Feb 10 '14 at 18:47

1 Answers1

5

Use the LinqToExcel.Row class (Documentation)

var excel = new ExcelQueryFactory("excelFileName");
var firstRow = excel.Worksheet().First();
var companyName = firstRow["CompanyName"];
Paul
  • 18,349
  • 7
  • 49
  • 56
  • From the man himself! Thanks, Paul! I'm a bit new so the First() never crossed my mind. Your documentation is very helpful! – Rob Jarvis Feb 10 '14 at 19:31