How to read an excel file using LinqToExcel project in c#?

Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 2502
Step 1: Use Nuget package manager to install LinqToExcel as shown under

PM> Install-Package LinqToExcel 

Step 2: Next write the below code

void ReadEmployeesFromExcel()


string excelPath = @"D:\EmployeeRecords.xlsx";

string sheetName = "Sheet1";

var excelFile = new ExcelQueryFactory(excelPath);

(from a in excelFile.Worksheet(sheetName) select a)
.Foreach(e=>Console.WriteLine(e["EmpID"] +"-----" + e["EmpName"] + "-------" + e["Address"]));


We are initializing an ExcelQueryFactory object where we are passing the excel file path and then from the object that we receive, we are reading in the Linq way and finally printing teh records by using the Foreach() method.

Comments or Responses

Login to post response