Search code examples
c#linq-to-excel

Linq to Excel Not Retrieving First Populated Row


I'm just starting out in Linq to Excel today, so I assume I've missed something rather simple.

I want to print the entire contents of an Excel Worksheet, But the ExcelQueryable object is not returning the first populated row.

The syntax I've used is as follows:

var excel_query_factory = new ExcelQueryFactory(directory);
var worksheet = excel_query_factory.Worksheet(worksheet_name);

The test spreadsheet is just a 5x5 table of the range B2:F6.

The query results are of the range C2:F6.

How should I specify that I do not wish the first populated row skipped?


Solution

  • If you're skipping the first row, it may be because it's thinking the first row is a header. Try the following:

    var excel_query_factory = new ExcelQueryFactory(directory);
    var worksheet = excel_query_factory.WorksheetNoHeader(worksheet_name);
    

    See the documentation here. Query a worksheet without a header row. See also the Query a specific range within a worksheet to use No Header as well.

    var yourRange = from c in excel_query_factory.WorksheetRangeNoHeader("B2", "F6")