using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text.Trim();
string strConn;
//strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
//"Data Source=E:\\20110624.xls;" +
//"Extended Properties=Excel 8.0;";
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source="+name+";" +
"Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [sheet1$]", strConn);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet);
this.GridView1.DataSource = myDataSet;
this.GridView1.DataBind();
}
}
转载地址: http://yulan0011.i.sohu.com/blog/view/183309582.htm