把datagrid生成了word文檔,並在ie顯示

下面代碼把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();   
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章