ASP.NET中读取Excel文件数据
程序代码 程序代码
string strPath = @"E:/test.xls";
string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + strPath + "';Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(mystring);
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
DataSet myDs = new DataSet();
myDa.Fill(myDs);
this.GridView2.DataSource = myDs.Tables[0];
this.GridView2.DataBind();
本文介绍了一种使用ASP.NET从Excel文件中读取数据的方法。通过连接字符串配置,并利用OleDbDataAdapter对象从指定的工作表中选择所有记录,然后填充到DataSet对象中,最后将数据绑定到GridView控件上进行展示。
683

被折叠的 条评论
为什么被折叠?



