Imports LinqToExcel
Imports System.Collections.Generic
Public Class ExcelAndCSVFileUtility
Public Shared Function ReadRecords(Of T)(fileName As String, sheetName As String) As IEnumerable(Of T)
Dim items = New ExcelQueryFactory(fileName).Worksheet(Of T)(sheetName)
For Each item As var In items
yield Return item
Next
End Function
End Class
We are creating an instance of the ExcelQueryFactory class by passing the full path to the Excel spreadsheet or CSV file.Then we are invoking the Worksheet method that expects the sheetName. Though, it is however optional.This method enables Linq queries against an Excel worksheet.We need to pass the TSheetData type to the Worksheet method. The TSheetData class returns the excel's row data as the specific Class Type .The yield moves the program pointer to and fro between caller and the collection.