Convert data in Excel to DataSet without using third-party plugins using C#
/// <summary> /// EXCEL data conversion DataSet /// </summary> /// <param name="filePath">Full path of file</param> /// <param name="search">Table name</param> /// <returns></returns> private DataSet GetDataSet(string fileName) { string strConn = "Provider=.12.0;Data Source=" + fileName + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1';"; OleDbConnection objConn = null; objConn = new OleDbConnection(strConn); (); DataSet ds = new DataSet(); //List<string> List = new List<string> { "Amount of collection", "Tariff payment", "Advance payment", "Excessive period", "Profit incurred" }; List<string> List = new List<string> { }; DataTable dtSheetName = (, new object[] { null, null, null, "TABLE" }); foreach (DataRow dr in ) { if (dr["Table_Name"].ToString().Contains("$") && !dr[2].ToString().EndsWith("$")) { continue; } string s = dr["Table_Name"].ToString(); (s); } try { for (int i = 0; i < ; i++) { (List[i]); string SheetName = List[i]; string strSql = "select * from [" + SheetName + "]"; OleDbDataAdapter odbcCSVDataAdapter = new OleDbDataAdapter(strSql, objConn); DataTable dt = [i]; (dt); } return ds; } catch (Exception ex) { return null; } finally { (); (); } }
The above is the entire content of this article, I hope you like it.