• 得对xls文件作操作


    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               
            }
        }

        protected void 预览Butto1_Click(object sender, EventArgs e)
        {
            string path = FileUpload1.PostedFile.FileName.ToString();
            string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Extended Properties=Excel 8.0;data source=" + path;
            string sql = "SELECT * FROM [Sheet1$]";// 查询语句

            OleDbConnection Conn = new OleDbConnection(ConnStr);

            DataSet ds = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, ConnStr);
            da.Fill(ds); //填充DataSet

            //输出,绑定数据
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
            Conn.Close();
        }

        protected void 写入Button_Click(object sender, EventArgs e)
        {
            string path = FileUpload1.PostedFile.FileName.ToString();
            string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Extended Properties=Excel 8.0;data source=" + path;
            string sql = "SELECT * FROM [Sheet1$]";// 查询语句

            OleDbConnection Conn = new OleDbConnection(ConnStr);
            Conn.Open();
            OleDbCommand Comm = new OleDbCommand(sql, Conn);
            OleDbDataReader sdr = Comm.ExecuteReader(CommandBehavior.CloseConnection);
            string str = "";
            while (sdr.Read())
            {
                if (str.IndexOf(sdr["部门"].ToString()) < 0)//获取部门
                {
                    str += sdr["部门"].ToString() + "<br/>";
                }
                //if (str.IndexOf(sdr["部门"].ToString() + "--" + sdr["岗位"].ToString()) < 0)//获取岗位
                //{
                //    str += sdr["部门"].ToString() + "--" + sdr["岗位"].ToString() + "<br/>";
                //}
                //Response.Write(string.Format("{0}--{1}--{2}--{3}--{4}--{5}<br />", sdr["工号"].ToString(), sdr["姓名"].ToString(), sdr["性别"].ToString(), sdr["部门"].ToString(), sdr["岗位"].ToString(), sdr["密码"].ToString()));
            }
            sdr.Close();
            Response.Write(str);
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>

    <body style="font-size:12px;">
        <form id="form1" runat="server">
        <asp:FileUpload ID="FileUpload1" runat="server" />&nbsp;
        <asp:Button ID="预览Butto1" runat="server" Text="预览数据" onclick="预览Butto1_Click" />&nbsp;
        <asp:Button ID="写入Button" runat="server" Text="写入数据库"
            onclick="写入Button_Click" />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
        </form>
    </body>
    </html>

  • 相关阅读:
    linux内存-swap
    linux内存-buffer和cache
    Linux内存-内存管理机制oom_killer
    HTTPS(二)证书合法性校验
    HTTPS(一)基础及连接建立
    docker镜像(一)overlayfs
    DNS(三)全局流量调度
    建造者模式(Builder Pattern)
    抽象工厂模式(Abstract Factory)
    工厂方法模式(Factory Method Pattern)
  • 原文地址:https://www.cnblogs.com/shuyu/p/1704714.html
Copyright © 2020-2023  润新知