原创  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();

发表于 @ 2004年09月23日 17:06:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:超长文章自动分页(含HTML),用ASP和Javascript实现  | 新一篇:[分享]千万数量级分页存储过程(效果演示)

  • 发表评论
  • 评论内容:
  •  
Copyright © evafly920
Powered by CSDN Blog