zoukankan      html  css  js  c++  java
  • 020. asp.net访问Excel文件

                            <asp:GridView ID="GridView1" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" Width="471px">
                                <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                                <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
                                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                                <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                                <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
                            </asp:GridView>
     protected void BtnOk_Click(object sender, EventArgs e)
        {
            try
            {
                string strConn;
                strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("学生成绩.xls") + ";" + "Extended Properties=Excel 8.0;";
                OleDbDataAdapter cmd = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
                DataSet ds = new DataSet();
                cmd.Fill(ds, "Excelstudent");
                this.GridView1.DataSource = ds.Tables["Excelstudent"].DefaultView;
                this.GridView1.DataBind();
                Response.Write("<script language=javascript>alert('恭喜您!Excel文件访问成功!')</script>");
            }
            catch
            {
                Response.Write("<script language=javascript>alert('很遗憾!Excel文件访问失败!')</script>");
            }
        }
  • 相关阅读:
    hdu 6201 dfs
    Oulipo POJ
    Kitchen Measurements UVALive
    Surf Gym
    hoj 13969 Racing Gems
    分块
    分块学习资料
    Jam's problem again HDU
    树的点分治
    Census UVA
  • 原文地址:https://www.cnblogs.com/wxylog/p/6144411.html
Copyright © 2011-2022 走看看