.net 对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();

posted @ 2008-03-21 09:36  zhangsir  阅读(350)  评论(0编辑  收藏  举报