using System.Collections.Generic;
namespace ReadingExcelData
public static List<Datacollection> dataCol = new List<Datacollection>();
public static DataTable ExcelToDataTable(string fileName)
using (var stream = File.Open(fileName, FileMode.Open, FileAccess.Read))
using (var reader = ExcelReaderFactory.CreateReader(stream))
var result = reader.AsDataSet(new ExcelDataSetConfiguration()
{ConfigureDataTable = (data) => new ExcelDataTableConfiguration()
DataTableCollection table = result.Tables;
DataTable resultTable = table["Sheet1"];
public static void PopulateInCollection(string fileName)
DataTable table = ExcelToDataTable(fileName);
for (int row = 1; row <= table.Rows.Count; row++)
for (int col = 0; col < table.Columns.Count; col++)
Datacollection dtTable = new Datacollection()
{rowNumber = row, colName = table.Columns[col].ColumnName, colValue = table.Rows[row - 1][col].ToString()};
public static string ReadData(int rowNumber, string columnName)
where colData.colName == columnName && colData.rowNumber == rowNumber
select colData.colValue).SingleOrDefault();
Console.WriteLine(e.Message);
public class Datacollection