Generic Program to read the Excel and CSV content using LinqToExcel library in C#

Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 322
using LinqToExcel;
using System.Collections.Generic;

public class ExcelAndCSVFileUtility
public static IEnumerable<T> ReadRecords<T>(string fileName,string sheetName)
var items = new ExcelQueryFactory(fileName)

foreach (var item in items) yield return item;

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.

Comments or Responses

Login to post response