public DataTable ExcelToDT()
        {
            DataTable dt = new DataTable();
            string filePath = Application.StartupPath + @"\Skills_TreeView\Skills.xls";

            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filePath + ";" + "Extended Properties=Excel 8.0;";
            using ( OleDbConnection conn = new OleDbConnection(strConn))
            {
                conn.Open();
                string strExcel = "select * from [sheet1$]";
                OleDbDataAdapter myCommand = new OleDbDataAdapter(strExcel, strConn);
                myCommand.Fill(dt);
            }           
            return dt;
        }





本文转载:CSDN博客