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)
    { }
    呵呵
  • 相关阅读:
    HDU 2476 String painter (*区间DP+基础Dp)
    hdoj 1405 The Last Practice
    hdu 2715 Herd Sums
    hdu 3617 Happy 2009
    hdu 1062 Text Reverse
    hdu 2716 Message Decowding
    hdu 1597 find the nth digit
    hdoj 1229 还是A+B
    hdu 1877 又一版 A+B
    hdoj 2045 不容易系列之(3)—— LELE的RPG难题
  • 原文地址:https://www.cnblogs.com/anjou/p/2132111.html
Copyright © 2011-2022 走看看