首页 > 其他分享 >上传Excel时如果获取Excel的所有的sheet页面

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

时间:2023-03-13 16:33:05浏览次数:38  
标签:Rows sheet string Excel DataSet SheetNames new 页面

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

相关文章