码迷,mamicode.com
首页 > 其他好文 > 详细

获取数据后导出Excel

时间:2014-09-25 18:19:47      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   io   os   ar   for   数据   sp   

List<PortResourceInfo> list = getList()//获取数据源

//导出excle

Response.Clear();
Response.ContentType = "application/excel";
Response.AddHeader("Content-Disposition", "inline;filename=" + HttpUtility.UrlEncode("端口资源.xls", Encoding.UTF8));
StringBuilder expStr = new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(expStr);
expStr.Append("<html><body>");
expStr.Append("<table><tr><th>序号</th><th>设备名称</th><th>设备型号</th><th>设备IP</th><th>端口名称</th><th>端口描述</th><th>端口带宽</th><th>Up/Down</th><th>端口状态</th></tr>");
int i = 1;
foreach (var item in list)
{
expStr.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td></tr>",
i, item.DeviceName, item.DiveceType,
item.IpAddress, item.IfName, item.Description,
item.IfSpeed, item.UpOrDown, item.IsFree
);
i++;
}

expStr.Append("</table></body></html>");
Page.EnableViewState = false;
Response.Write(sw.ToString());
Response.End();

获取数据后导出Excel

标签:des   style   http   io   os   ar   for   数据   sp   

原文地址:http://www.cnblogs.com/juefeiye/p/3993163.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!