17,740
社区成员
发帖
与我相关
我的任务
分享
Response.ClearContent();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName1.xls");
//Response.AppendHeader("Content-Disposition", "attachment;filename=FileName1.doc");
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.ContentType = "application/excel";//设置输出文件类型为excel文件。
//Response.ContentType = "application/word";//设置输出文件类型为word文件。
//导出gridview部分
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
gridview.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.Flush();
Response.End();