zoukankan      html  css  js  c++  java
  • 导出GridView到Excel中的关键之处

    导出GridView到Excel中的关键之处
    用法: ToExcel(GVStaff, TextBox1.Text);

    public static void ToExcel(System.Web.UI.Control ctl,string FileName)
            {
                HttpContext.Current.Response.Charset ="UTF-8";
                HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
                HttpContext.Current.Response.ContentType ="application/ms-excel";
                HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+""+FileName+".xls");
                ctl.Page.EnableViewState =false;
                System.IO.StringWriter  tw = new System.IO.StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(tw);
                ctl.RenderControl(hw);
                HttpContext.Current.Response.Write(tw.ToString());
                HttpContext.Current.Response.End();
            }        
         
    必须有下面这句!否则不会通过!
    public override void VerifyRenderingInServerForm(Control control)
        {
            // Confirms that an HtmlForm control is rendered for
        }

     

  • 相关阅读:
    erlang遍历目录
    C/C++ makefile自动生成工具(comake2,autotools,linux),希望能为开源做点微薄的贡献!
    shell 文件操作
    互联网分享知识(一)
    分页查询,你真的懂吗?
    awk神器
    Unicode编码解码在线转换工具
    awk 留底
    软件开发真的这么简单吗?
    php性能优化
  • 原文地址:https://www.cnblogs.com/skyblue/p/674587.html
Copyright © 2011-2022 走看看