c#解析excel

       public DataSet GetDsByName(string ExcelName)
        {
            string strCon;
            strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +  ExcelName + "; Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
            OleDbConnection olecon = new OleDbConnection(strCon);
            olecon.Open();
            DataTable dt = olecon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] { null, null, null, "TABLE" });
            string sheetName = dt.Rows[0]["TABLE_NAME"].ToString();//获取Excel表名
            OleDbDataAdapter myda = new OleDbDataAdapter("SELECT * FROM [" + sheetName + "] ", strCon);
            DataSet myds = new DataSet();
            myda.Fill(myds);
            olecon.Close();
            return myds;
        }

你可能感兴趣的:(String,properties,C#,Excel,null,dataset)