C#读取Excel2007

private DataSet GetExcelData(string str)
    {
        string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + str + ";Extended Properties=\"Excel 12.0;HDR=YES\"";
        OleDbConnection myConn = new OleDbConnection(strCon);
        string strCom = " SELECT * FROM [Sheet1$]";
        myConn.Open();
        OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
        DataSet myDataSet = new DataSet();
        myCommand.Fill(myDataSet);
        myConn.Close();
        return myDataSet;
    }

posted @ 2011-11-08 10:35  高捍得  阅读(355)  评论(0编辑  收藏  举报