In asp.net 2.0, how to use gridview to display the content from the created EXCEL file is actually very simple. The following is a simple code snippet
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection DBConnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
Server.MapPath("~/App_Data/demo1.xls") + ";" + "Extended
Properties="Excel 8.0;HDR=Yes"");
DBConnection.Open();
string SQLString = "SELECT * FROM [Sheet1$]";
OleDbCommand DBCommand = new OleDbCommand(SQLString, DBConnection);
IDataReader DBReader = DBCommand.ExecuteReader();
GridView1.DataSource = DBReader;
GridView1.DataBind();
DBReader.Close();
DBConnection.Close();
}
Among them, put demo1.xls in the app_data directory, and use select * from [Sheet1$] to take out the contents of sheet1.