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的例子
|
|