将Gridview导出到Excel
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)
{
}
最新文章
- Python学习日志(二)
- 【原】iOS学习之Masonry第三方约束
- App开放接口api安全性的设计与实现
- 第64课 C++中的异常处理(上)
- 手机web页面制作时的注意事项
- JavaScript 风格指导(Airbnb版)
- 【Java】Checked、Unchecked Exception
- HTML7常用的类型刮刮乐 光棒效果
- 优化 or 语句
- Java NIO系列教程(六) 多路复用器Selector
- 如何使用Live CD来修复Grub / Grub2
- HTML5中的History对象
- Git删除文件
- 结合 spring 使用阿里 Druid 连接池配置方法
- 在react中使用intro.js的的一些经验
- u3d 场景资源打包
- 2018.09.21 codeforces1051D. Bicolorings(线性dp)
- 16_常用API_第16天(正则表达式、Date、DateFormat、Calendar)_讲义
- [转帖] .net 2.1 是 LTS长期支持版本.
- Linux命令详解-printf