在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/// <summary> /// 读取EXCEL数据 /// </summary> /// <param name="Path"></param> /// <returns></returns> public static System.Data.DataSet ExcelToDS(string Path) { string strConn = string.Empty; string version = Path.Substring(Path.Length - 1); if (version.Equals("s")) { strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;"; } else { strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;"; } OleDbConnection conn = new OleDbConnection(strConn); System.Data.DataSet ds = null; try { conn.Open(); //System.Data.DataTable schemaTable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null); System.Data.DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] { null, null, null, "TABLE" }); string tableName = schemaTable.Rows[0][2].ToString().Trim(); string strExcel = ""; OleDbDataAdapter myCommand = null; strExcel = "select * from [" + tableName + "]"; myCommand = new OleDbDataAdapter(strExcel, strConn); ds = new System.Data.DataSet(); myCommand.Fill(ds, tableName); return ds; } catch (Exception e) { conn.Close(); } finally { conn.Close(); } return ds; }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论