GridView导出到excel
来源:互联网 发布:mac vnc连接windows 编辑:程序博客网 时间:2024/05/22 06:19
本文是asp.net Gridview操作小积累,用得着的可以参考一下,本例子思想来源于webcast
前台关键代码:
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:Button ID="butExport" runat="server" Text="Export"
onclick="butExport_Click" />
后台关键代码:
protected void butExport_Click(object sender, EventArgs e)
{
Response.Clear();//清除缓冲区所有内容,防止影响导入到excel的数据
Response.Buffer = true; //response缓存
Response.Charset = "GB2312"; //设置输出流字符集
Response.AppendHeader("Content-Disposition","attachment;filename="+@"d:/person.xls"); //设置excel存放路径
//如果设置GetEncoding(“GB2312”)可能会出现乱码问题
Response.ContentEncoding = System.Text.Encoding.UTF8;
//设置为excel文件输出
Response.ContentType = "application/ms-excel";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlWriter = new HtmlTextWriter(oStringWriter);
this.GridView1.RenderControl(oHtmlWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
//下面类必须重写,否则运行时会报错
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
- 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
- ld.so.conf
- 施密特:Google六个月内推出高品质平板电脑
- 微软crypto API
- asp网站实现邮件的发送(注册为例)
- [shell] expect完整介绍
- GridView导出到excel
- GridView手动在后台增加-删除(1)
- Windows下截获程序的异常并进行处理
- C++ split字符串
- 嵌入式开发软件简介
- SharePoint2010项目中如何使用HttpModule
- define
- asp jmail和asp web的邮件发送(带附件)
- 面向对象的JavaScript