string StrConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + " Data Source=" + path + ";" + "Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";//路径的正确性 OleDbConnection con = new OleDbConnection(StrConn); con.Open();//打开连接 System.Data.DataTable SheetNames = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });//获取列表名称 string[] TableNames = new string[SheetNames.Rows.Count]; for (int k = 0; k < SheetNames.Rows.Count; ++k) { TableNames[k] = SheetNames.Rows[SheetNames.Rows.Count - k - 1]["TABLE_NAME"].ToString();//遍历 } DataSet ds = new DataSet(); foreach (string item in TableNames) { DataSet ds1 = new DataSet(); OleDbDataAdapter myCommand = null; string strExcel = string.Format("select * from [{0}]", item); myCommand = new OleDbDataAdapter(strExcel, StrConn);
}
标签:Rows,sheet,string,Excel,DataSet,SheetNames,new,页面 From: https://www.cnblogs.com/sexintercourse/p/17211878.html