连接Excel库代码

来源:互联网 发布:淘宝店招模板代码 编辑:程序博客网 时间:2024/05/21 18:40
连接Excel库代码
System.Data.OleDb.OleDbConnection 
con1=new System.Data.OleDb.OleDbConnection(); 
string constr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C://test2.xls;Extended Properties=Excel 8.0;";
con1.ConnectionString=constr; 
con1.Open();
System.Data.OleDb.OleDbCommand com1=new System.Data.OleDb.OleDbCommand(); 
com1.CommandText="SELECT ww1 FROM [Sheet1$] "; 
com1.Connection=con1; 
System.Data.OleDb.OleDbDataAdapter ap=new System.Data.OleDb.OleDbDataAdapter(com1);  
ap.Fill(ds);   
this.DataGrid1.DataSource=ds;   
this.DataGrid1.DataBind();
原创粉丝点击