zoukankan      html  css  js  c++  java
  • 将GridView中的结果导出成Excel文件格式

     protected void Button1_Click(object sender, EventArgs e)
        {
            Export("application/ms-excel", "Nor.xls");
        }

        private void Export(string FileType,string FileName)
        {
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response .AppendHeader ("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode (FileName ,Encoding.UTF8).ToString ());
            Response .ContentType = FileType ;

            this .EnableViewState = false ;
            StringWriter tw = new StringWriter();

            HtmlTextWriter hw = new HtmlTextWriter (tw);
            GridView1.RenderControl (hw);
            Response .Write (tw.ToString ());
            Response.End ();
        }

    //没有这个复写方法,会报错。
        public override void VerifyRenderingInServerForm(Control control)
        {
     
        }

  • 相关阅读:
    每日总结4.25
    每日总结4.24
    每日总结4.23
    每日博客4.22
    每日博客4.21
    每日博客4.20
    每日总结4.19
    每日总结4.16
    每日总结4.15
    每日总结4.14
  • 原文地址:https://www.cnblogs.com/daiweixm/p/1527220.html
Copyright © 2011-2022 走看看