您的位置:首页 > 其它

实现将Web页面的内容,Export To Excel的功能

2006-08-09 15:52 543 查看

public void ToExcel(System.Web.UI.Control ctl, string FileName)






{


HttpContext.Current.Response.Charset = "UTF-8"; // 或UTF-7 以防乱码


HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;


HttpContext.Current.Response.ContentType = "application/ms-excel";


HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName + ".xls");


ctl.Page.EnableViewState = false;


System.IO.StringWriter tw = new System.IO.StringWriter();


System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);


ctl.RenderControl(hw);


HttpContext.Current.Response.Write(tw.ToString());


HttpContext.Current.Response.End();


ctl.Page.EnableViewState = true;


}





http://www.cnblogs.com/skywind/archive/2006/08/08/470699.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: