上传Excel时如果获取Excel的所有的sheet页面

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);
}

 

posted on 2023-03-13 16:25  漫思  阅读(30)  评论(0编辑  收藏  举报

导航