How to read an excel file using LinqToExcel project in

Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 580
Step 1: Use Nuget package manager to install LinqToExcel as shown under

PM> Install-Package LinqToExcel 

Step 2: Next write the below code

Private Sub ReadEmployeesFromExcel()

Dim excelPath As String = "D:\EmployeeRecords.xlsx"

Dim sheetName As String = "Sheet1"

Dim excelFile = New ExcelQueryFactory(excelPath)

(From a In excelFile.Worksheet(sheetName)a).ToList().Foreach(Function(e) Console.WriteLine(e("EmpID") + "-----" + e("EmpName") + "-------" + e("Address")))

End Sub

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