<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</form>
要記得加 using System.Data.OleDb;
protected void Page_Load(object sender, EventArgs e)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Book1.xls; Extended Properties=Excel 8.0;";
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet, "ExcelInfo");
this.GridView1.DataSource = myDataSet.Tables["ExcelInfo"].DefaultView;
this.GridView1.DataBind();
}
全站熱搜
留言列表