码迷,mamicode.com
首页 > 其他好文 > 详细

将Gridview导出到Excel

时间:2015-05-12 11:07:20      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

GridViewToExcel(EdceExcelGV, "application/ms-exce","xxxxxx表");

 

protected void GridViewToExcel(Control ctrl, string FileType, string FileName)
{

/*Response.Charset = "GB2312";
Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
HttpContext.Current.Response.ContentType = FileType;//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
this.EnableViewState=false;
StringWriter sw=new StringWriter ();
HtmlTextWriter htw=new HtmlTextWriter(sw);
ctrl.RenderControl(htw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();*/

Response.ClearContent();
Response.BufferOutput = true;
Response.Charset = "utf-8";
Response.ContentType = FileType;
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(FileName) + ".xls");
this.EnableViewState=false;
StringWriter sw=new StringWriter ();
HtmlTextWriter htw=new HtmlTextWriter(sw);
ctrl.RenderControl(htw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}

将Gridview导出到Excel

标签:

原文地址:http://www.cnblogs.com/jinhaoObject/p/4496416.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!