string source = "D:\\book1.xls";//execel文件的完整路径
        string sqlconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + source + ";Extended Properties=Excel 8.0";
        
string sql = "SELECT * FROM [Sheet1$]";
        OleDbCommand oldcom 
= new OleDbCommand(sql, new OleDbConnection(sqlconn));
        OleDbDataAdapter oleda 
= new OleDbDataAdapter(oldcom);
        DataSet ds 
= new DataSet();
        oleda.Fill(ds, 
"[Sheet1$]");
        
this.Label1.Text = ds.Tables[0].TableName;
        
this.GridView1.DataSource = ds;
        
this.GridView1.DataMember = "[Sheet1$]";
        
this.GridView1.DataBind();
posted on 2008-02-18 14:08  风之旖旎  阅读(608)  评论(2)    收藏  举报