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

    导出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
        }

    邀月注:本文版权由邀月和博客园共同所有,转载请注明出处。
    助人等于自助!  3w@live.cn
  • 相关阅读:
    CF1093F Vasya and Array
    CF1093D Beautiful Graph
    mysql主主同步
    mysql主从机制的部署与应用
    什么是多项式?
    从线性逼近到多项式逼近:泰勒级数
    机器学习--boosting家族之XGBoost算法
    倾情大奉送--Spark入门实战系列
    [机器学习笔记] 什么是分类,什么是回归?
    kafka中处理超大消息的一些考虑
  • 原文地址:https://www.cnblogs.com/downmoon/p/1019303.html
Copyright © 2011-2022 走看看