zoukankan      html  css  js  c++  java
  • GridView导出Excel

    GridView导出Excel:
    /// <summary>
    /// 需要重写GridView所在的页面的VerifyRenderingInServerForm事件
    /// public override void VerifyRenderingInServerForm(Control control)
    /// { }
    /// </summary>
    private void ExportToExcel(GridView gv, string fileName)
    {
        Response.Clear();
        Response.Buffer 
    = true;
        Response.Charset 
    = "gb2312";
        Response.Write(
    "<meta http-equiv=Content-Type content=text/html;charset=gb2312>");
        Response.AppendHeader(
    "Content-Disposition""attachment;filename=" + fileName);
        Response.ContentEncoding 
    = System.Text.Encoding.GetEncoding("gb2312"); ;
        Response.ContentType 
    = "application/vnd.xls";
        
    this.EnableViewState = false;
        StringWriter tw 
    = new StringWriter();
        HtmlTextWriter hw 
    = new HtmlTextWriter(tw);
        gv.RenderControl(hw);
        Response.Output.Write(tw.ToString());
        Response.Flush();
        Response.End();
    }

    /// <summary>
    /// 配合 Gridvidew 汇出Excel使用
    /// </summary>
    public override void VerifyRenderingInServerForm(Control control)
    { }
    呵呵
  • 相关阅读:
    重建二叉树
    替换空格
    四种类型转换符
    KVC和KVO简单介绍
    多线程之GCD的理解
    iOS常用代码
    iOS开发一些经常用到的第三方框架
    AS3 about Array.splice()
    sharedobject
    FlashBuilder的快捷键
  • 原文地址:https://www.cnblogs.com/anjou/p/2132111.html
Copyright © 2011-2022 走看看