zoukankan      html  css  js  c++  java
  • asp.net gridview 导出到excl

      public void Export_EXCL(GridView GridView1)
        {
            /**
             * 如果打印全部数据,则加上注视的代码
             * */
            //GVExport.AllowPaging = false;
            //GVExport.AllowSorting = false;
            //GVExport.DataSource = null;
            //GVExport.DataBind();
            DateTime dt = DateTime.Now;
            Response.ClearContent();
            Response.Buffer = true;
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            string filename = "export_" + dt.ToString("yyyyMMddHHmm") + ".xls";
            string[] browsers = { "Firefox", "AppleMAC-Safari", "Opera" }; //针对FF、Safari、Opera 设置编码
            string browser = Request.Browser.Browser;
            string attachment = string.Empty;
            if (Array.IndexOf<string>(browsers, browser) != -1)
            {
                attachment = "attachment; filename=" + filename;
            }
            else
            {
                attachment = "attachment; filename=" + Server.UrlEncode(filename);
            }
            Response.AddHeader("content-disposition", attachment);
            Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>");
            Response.ContentType = "application/ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            GridView1.RenderControl(htw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
    
        public override void VerifyRenderingInServerForm(Control control)
        {
    
        }
    View Code
  • 相关阅读:
    操作系统六文件管理
    Educational Codeforces Round 38 (Rated for Div. 2) ABCD
    51nod 1100 斜率最大
    51nod 最小方差
    51nod 1065 最小正子段和
    P1280 尼克的任务
    牛客小白月赛2
    Codeforces Round #210 (Div. 1) B 二分+dp
    江西财经大学第一届程序设计竞赛
    51nod 1596 搬货物
  • 原文地址:https://www.cnblogs.com/tiancai/p/13541334.html
Copyright © 2011-2022 走看看