zoukankan      html  css  js  c++  java
  • GridView導出Excel

      protected void ExportToExcel(string FileType, string FileName)
        {
            Response.Clear();
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.HeaderEncoding = System.Text.Encoding.Default;
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
            Response.ContentType = FileType;
            StringWriter tw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(tw);
            GridView1.AllowPaging = false;
            Bind();
            GridView1.RenderControl(htw);
            Response.Write(tw.ToString());
            Response.End();
            GridView1.AllowPaging = true;
            Bind();
        }
     protected void txt_Out_Click(object sender, EventArgs e)
        {
            if (GridView1.Rows.Count < 1)
            {
                Response.Write("<script>alert('沒有資料')</script>");
                return;
            }
    
            ExportToExcel("application/ms-excel", "Data.xls");
        }
  • 相关阅读:
    程序员学习提高必看的一篇文章
    SpringAOP拦截器的代理机制
    springboot03_RabbitMQ
    Docker_02
    Docker_01
    Redis_02
    Redis_01
    关于Linux下内存和Swap
    密码学DAY2
    密码学DAY1_02
  • 原文地址:https://www.cnblogs.com/siri/p/2954540.html
Copyright © 2011-2022 走看看