CSDN博客

img evafly920

datagrid生成了word文档

发表于2004/9/23 17:06:00  963人阅读

下面代码把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();

阅读全文
0 0

相关文章推荐

img
取 消
img