分享

将数据导入Excle

 实力决定地位 2010-04-24
 protected void Button1_Click(object sender, EventArgs e)
    {
       // List<LoginLog> lis = new List<LoginLog>();
     // string sql = "select top 10 * from LoginLog where loginid not in (select top (10 * (@cuttpager-1)) loginid from LoginLog order by loginid) order by loginid";
       // string path= ExCEl.query_table_getdata(@"D:/tex/text/Excle/",sql);
     //  DataTable tb = DBHper.GetTable(sql,new SqlParameter("@cuttpager",pager));
        List<LoginLog> list = LoginLogService.GetList2(pager);

       
        string str = "<table width=100% border=1 bgcolor=black cellspacing=1>";
        str += "<tr bgcolor=yellow>";
        str += "<td width=100px style='text-align:center '>" + "登陆ID" + "</td>";
        str += "<td width=100px style='text-align:center '>" + "用户名称" + "</td>";
        str += "<td width=100px style='text-align:center '> " + "登陆时间" + "</td>";
        str += "<td width=100px style='text-align:center '>" + "登陆IP" + "</td>";
        str += "<td width=100px style='text-align:center '>" + "登陆时候成功" + "</td>";
        str += "<td width=100px style='text-align:center '>" + "登陆描述" + "</td>";
        str += "</tr>";
        foreach (LoginLog log in list)
        {
            str += "<tr bgcolor=white>";
            str += "<td width='100px' style='text-align:center '>" + log.LoginId + "</td>";
            str += "<td width='100px' style='text-align:center '>" + log.UserId + "</td>";
            str += "<td width='100px' style='text-align:center '>" + log.LoginTime + "</td>";
            str += "<td width='100px' style='text-align:center '>" + log.LoginUserIp + "</td>";
            if (log.IfSuccess == 1)
            {
                str += "<td width='100px' style='text-align:center '>" + "成功" + "</td>";
            }
            else
            {
                str += "<td width='100px' style='text-align:center '>" + "失败" + "</td>";
            }
           
            str += "<td width='100px' style='text-align:center '>" + log.LoginDesc + "</td>";
            str += "</tr>";
        }
        str += "</table>";
        using (StreamWriter writer = new StreamWriter(Server.MapPath("~/Excle/TextFile.xls"), false, System.Text.Encoding.Default))
        {
            writer.WriteLine(str);
            Response.Redirect("~/Excle/TextFile.xls");
        }
 
}
这是一个简单的将数据导入Excle的例子
       

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约