Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve data from Excel using linq?

Tags:

c#

excel

linq

I like to retrieve the data from excel sheet using linq, I saw ExcelqueryFactory for that in some sites. I don't know the namespace or reference for that. I am using .net3.5 framework(visual studio2008). Is it possible to use it in .net3.5

like image 965
ratty Avatar asked Jan 04 '11 11:01

ratty


1 Answers

I think ExcelQueryFactory come from .net framework 4.0 . We need to inculde dll for access that class in .net3.5.From below link we can get that.

http://code.google.com/p/linqtoexcel/source/browse/trunk/src/LinqToExcel/ExcelQueryFactory.cs?r=50

Below example code show how we retrieve from Excel using ExcelQueryFactory

var book = new ExcelQueryFactory("pathToExcelFile");
var australia = from x in book.Worksheet()
                where x["Country"] == "Aust"
                select new
                {
                   Country = x["Country"],
                   BookCode = x["Code"],
                   BookName = x["Name"]
                };
like image 178
ratty Avatar answered Oct 21 '22 13:10

ratty