Use C # to convert data from Excel into a dataset without the help of a third-party plug-in
<summary>////Excel Data Conversion DataSet///</summary>/<param name= "FilePath" > File full path </param> ; <param name= "search" > Table name </param>//<returns></returns> private DataSet GetDataSet (Strin G fileName) {string strconn = "Provider=microsoft.ace.oledb.12.0;data source=" + FileName + "; Extended properties= ' Excel 12.0; Hdr=yes;imex=1 '; "; OleDbConnection objconn = null; objconn = new OleDbConnection (strconn); objConn.Open (); DataSet ds = new DataSet (); list<string> List = new List<string> {"Payment amount", "Pay duty", "Prepaid fee", "overdue", "to account Profit"}; list<string> List = new List<string> {}; DataTable dtsheetname = objconn.getoledbschematable (OleDbSchemaGuid.Tables, new object[] {null, NULL, NULL, "TABLE"}); foreach (DataRow dr in Dtsheetname.rows) {if (dr["table_name"]. ToString (). Contains ("$") &&!dr[2]. ToString (). EndsWith ("$")) {continue; } string s = dr["table_name"]. ToString (); List.add (s); try {for (int i = 0; i < List.count; i++) {ds. Tables.add (List[i]); String sheetname = List[i]; String strSQL = "SELECT * FROM [" + SheetName + "]"; OleDbDataAdapter odbccsvdataadapter = new OleDbDataAdapter (strSQL, objconn); DataTable dt = ds. Tables[i]; Odbccsvdataadapter.fill (DT); } return DS; } catch (Exception ex) {return null; } finally {objconn.close (); Objconn.dispose (); } }
The above mentioned is the whole content of this article, I hope you can like.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C # converts data from Excel into a dataset
This address: http://www.paobuke.com/develop/c-develop/pbk23092.html
Related content convert any type of generic collection to an instance of SQLXML data format in C # How to choose how to implement XSL transformations using ArrayList, HashTable, List, dictionary arrays C # Several usages of using directives in C #
C # Method of stopping threading in C # A typical flaw for beginners in C # using the @ Declaration variable example (verbatim identifier) C # Summary of common methods of string class
C # converts data from Excel into a dataset