LINQ is a powerful and well-known, can you extend LINQ to read Excel?
The answer, of course, is yes.
Linqtoexcel is a. NET open source class library that implements querying an Excel table using LINQ syntax.
In the NuGet search download install to the project, add the using Linqtoexcel reference, and then see the following code using:
Rtb_result.text ="use of Linqtoexcel (supports Excel2003 and the following versions. ) \ n"; OpenFileDialog Excelopener=NewOpenFileDialog (); Excelopener.filter="Excel file |*.xls"; if(Excelopener.showdialog () = =DialogResult.OK) {varExcel =Newexcelqueryfactory (excelopener.filename); varDataList = fromCinchExcel. Worksheet ("Mathematics") SelectC; intCount =Datalist.count (); Rtb_result.appendtext (string. Format ("reading from Excel to the {0} line information will be displayed in the TextBox. \ n", Count)); foreach(varMappinginchdataList) { stringDbstr =string. Format ("{0} {1} {2}", mapping["School Number"]. ToString (), mapping["name"]. ToString (), mapping["Achievements"]. ToString ()); Rtb_result.appendtext (DBSTR); Rtb_result.appendtext ("\ n"); } rtb_result.appendtext ("finished reading. "); } Else{Rtb_result.appendtext ("no appropriate Excel file was selected. "); }
To form the Excel table above, read the following:
Reference:
Official website: https://github.com/paulyoder/LinqToExcel
Abstract: http://typecastexception.com/post/2013/09/25/C-Query-Excel-and-CSV-Files-Using-LinqToExcel.aspx
Note:
The only reason to read the XLS in the example is because xlsx fails to read the native old.
I try to search the solution, is generally download AccessDatabaseEngine.exe, but not, because the project just need to read a table content and update to the database, there is no solution to this problem ...
Http://www.cnblogs.com/dwfbenben/archive/2011/12/13/2286058.html
The above is a suspected solution, do not know that can not be ...
Linqtoexcel:linq Querying Excel spreadsheets