页面放一个gridview,一个button,在button的点击事件中写如下代码:
如果不能读取,一般是文件夹没有权限,要有对文件夹的操作权限
如果不能读取,一般是文件夹没有权限,要有对文件夹的操作权限
string strPath = @"D:\Excel\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);
GridView1.DataSource = myDs.Tables[0];
GridView1.DataBind();