GridView导出到Excel
来源:互联网 发布:r语言与数据分析实战 编辑:程序博客网 时间:2024/06/07 01:32
protected void Button1_Click(object sender, EventArgs e) //导出
{
Export("application/ms-excel", "info.xls"); //现在导出Excel,如需要导出word,只需要将application/ms-word 更改即可。第二个参数代表导出后文件的名称以以及格式
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control) //必加事件,不加会报“类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内”错误
{
}
{
Export("application/ms-excel", "info.xls"); //现在导出Excel,如需要导出word,只需要将application/ms-word 更改即可。第二个参数代表导出后文件的名称以以及格式
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control) //必加事件,不加会报“类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内”错误
{
}
- GridView导出到Excel
- GridView导出到Excel
- GridView导出到Excel
- GridView导出到Excel
- gridview 导出到excel
- 导出GridView到Excel
- 导出GridView到Excel
- GridView导出到Excel
- GridView导出到Excel
- GridView 导出到EXCEL
- GridView导出到Excel
- GridView 导出到 Excel
- Gridview导出到excel
- GridView 导出到excel
- 导出Gridview到excel
- GridView导出到Excel
- GridView导出到Excel
- GridView导出到excel
- centOS怎样强制卸载PHP以及自定义安装PHP
- 字符串连接
- 今天买了两本书
- .net 不让浏览器缓存
- JBOSS AS7 数据源配置一条龙+jersey 发布应用关键点
- GridView导出到Excel
- JBoss AS7 用户指南
- [USACO]clocks
- Linux进程控制
- mvc 发送邮件(可选多人)
- .net 常用格式化公式
- C下学生管理系统:从文件中读取30位学生的信息(含邮箱),并实现简单的增、删、查找、统计(邮箱使用人数)。---附程序哦!
- OGNL表达式struts2标签“%,#,$”
- FCKeditor的简易配置