使用LINQ語法查詢Excel的.NET庫:LinqToExcel

jopen 9年前發布 | 21K 次閱讀 .NET開發 LinqToExcel

Linq to Excel 是一個 .Net 庫能夠讓你使用LINQ語法來查詢Excel電子表格。

Adding LinqToExcel to your project

NuGet

You can use NuGet to quickly add LinqToExcel to your project. Just search for linqtoexcel and install the package.

Manually Add References

If you don't want to use the NuGet package you can Download the latest files and add the following references to your project
* LinqToExcel.dll
* Remotion.Data.Linq.dll

x64 Support

If you want LinqToExcel to run in a 64 bit application, make sure to use the 64 bit version of the library.

You will also need to make sure to have the 64 bit version of the Access Database Engine installed on the computer.

Query a worksheet with a header row

The default query expects the first row to be the header row containing column names that match the property names on the generic class being used. It also expects the data to be in the worksheet named "Sheet1".

var excel = new ExcelQueryFactory("excelFileName");
var indianaCompanies = from c in excel.Worksheet<Company>()
                       where c.State == "IN"
                       select c;

Query a specific worksheet by name

Data from the worksheet named "Sheet1" is queried by default. To query a worksheet with a different name, pass the worksheet name in as an argument.

var excel = new ExcelQueryFactory("excelFileName");
var oldCompanies = from c in repo.Worksheet<Company>("US Companies") //worksheet name = 'US Companies'
                   where c.LaunchDate < new DateTime(1900, 1, 1)
                   select c;

項目主頁:http://www.baiduhome.net/lib/view/home/1437535948631

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!