繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> datagrid生成了word文档

datagrid生成了word文档

2007-09-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:下面代码把datagrid生成了word文档,并在ie显示 //生成 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=RoadRepair.doc"); Response.ContentType = "application/vnd....
关键字:datagrid 生成 文档 word

下面代码把datagrid生成了word文档,并在ie显示

//生成

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

Response.ContentType = "application/vnd.ms-word" ;//指定生成文件的类型

HttpContext.Current.Response.Charset = "";

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

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

System.Web.UI.HTMLTextWriter hw=new System.Web.UI.HTMLTextWriter(tw)

DataGrid1.RenderControl(hw);//datagrid转成string

HttpContext.Current.Response.Write(hw.tosting());

HttpContext.Current.Response.End();

//显示

Response.ClearContent();

Response.ClearHeaders();

Response.ContentType="application/msword";

Response.WriteFile("RoadRepair.doc");

Response.Flush();

Response.Close();

Trackback: http://tb.blog.csdn.net/TrackBack.ASPx?PostId=114506

责任编辑:admin
相关文章