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");
        }
  • 相关阅读:
    kafka 常见面试题
    分布式-redis实现分布式锁
    java info信息中打印异常堆栈
    11.盛水最多的容器
    445.两数相加
    328. 奇偶链表
    7中join查询
    Linux基础学习05
    Linux基础学习04
    Linux基础学习03
  • 原文地址:https://www.cnblogs.com/siri/p/2954540.html
Copyright © 2011-2022 走看看