C#找到Excel中的所有Sheetname的方法

#region 找到Excel的所有Sheetname
        /// <summary>
        /// 找到Excel的所有Sheetnames
        /// </summary>
        /// <returns>返回Sheetnames</returns>
        private List<string> ExcelSheetName()
        {
            string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txt_Filepath.Text + ";Extended Properties=Excel 8.0;";
            List<string> sheetNames = new List<string>();
            using (OleDbConnection con = new OleDbConnection(conString))
            {
                con.Open();
                System.Data.DataTable sheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "table" });
                con.Close();
                foreach (DataRow var in sheetName.Rows)
                {
                    sheetNames.Add(var[2].ToString());
                }
            }
            return sheetNames;
        }
        #endregion

posted @ 2010-07-29 13:28  JasonNET  阅读(2029)  评论(0编辑  收藏  举报