C#Winformd读取excel文件数据转化为DataTable

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


 
  

你可能感兴趣的:(C#编程技术)