您的位置:首页 > 编程语言 > ASP

ASP.NET中操作Word和Excel(二)

2007-03-04 20:05 393 查看
使用HttpContext对象,导出到word。这个比较通用,也可以导出到excel等。可将整个页面(Page),或者DataGrid,DataList等控件使用RenderControl()方法到word,提示用户选择下载存放地址。


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


HttpContext.Current.Response.Charset = "UTF-8";


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


HttpContext.Current.Response.ContentType = filetype;


//HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword


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


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


gv.RenderControl(hw);


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


HttpContext.Current.Response.End();

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: