下面代码把datagrid1的内容导出为word文件
--------------------------------------------------------------------------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;
DataGrid1.Page.EnableViewState = false;System.IO.StringWriter tw=new  System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw=new System.Web.UI.HtmlTextWriter(tw);//System.Web.UI.Html32TextWriter ;DataGrid1.Columns[0].Visible=false;//不打印的列隐藏
DataGrid1.Columns[1].Visible=false;
DataGrid1.Columns[2].Visible=true;//要打印的列显示
DataGrid1.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());//写入word文件
HttpContext.Current.Response.End();