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 '> " + "登陸時(shí)間" + "</td>";
str += "<td width=100px style='text-align:center '>" + "登陸IP" + "</td>";
str += "<td width=100px style='text-align:center '>" + "登陸時(shí)候成功" + "</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");
}
}
這是一個(gè)簡(jiǎn)單的將數(shù)據(jù)導(dǎo)入Excle的例子
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。