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
        }

     

  • 相关阅读:
    【转载】高内聚低耦合
    【转载】locate命令的使用
    【转载】C内存对齐
    【原创】_INTSIZEOF 内存按照int对齐
    【转载】free查看内存
    Hive查询Join
    Hive数据查询
    Hive导入数据
    Hive表的修改Alter
    Hive中排序和聚集
  • 原文地址:https://www.cnblogs.com/skyblue/p/674587.html
Copyright © 2011-2022 走看看