zoukankan      html  css  js  c++  java
  • asp.net 将GridView导出到Excel


       /// <summary>
        
    /// GridView导出Excel
        
    /// </summary>
        
    /// <param name="pageLocal">要导出的页面</param>
        
    /// <param name="gvVal">要导出的GridView</param>
        
    /// <param name="sFileName">导出后的文件名</param>
        public static void ExcelExport(Page pageLocal, GridView gvVal, string sFileName)
        {
            
    string attachment = "attachment; filename=" + sFileName + ".xls";
            pageLocal.Response.ClearContent();
            pageLocal.Response.AddHeader(
    "content-disposition", attachment);
            pageLocal.Response.ContentType 
    = "application/ms-excel";
            StringWriter sw 
    = new StringWriter();
            HtmlTextWriter htw 
    = new HtmlTextWriter(sw);

            
    // Create a form to contain the grid
            HtmlForm frm = new HtmlForm();
            gvVal.Parent.Controls.Add(frm);
            frm.Attributes[
    "runat"= "server";
            frm.Controls.Add(gvVal);
            frm.RenderControl(htw);

            
    //GridView1.RenderControl(htw);
            pageLocal.Response.Write(sw.ToString());
            pageLocal.Response.End();
        }


  • 相关阅读:
    C语言位操作
    Ribbon负载规则的替换
    Nginx 的配置文件
    Nginx 操作常用的命令
    Nginx 是什么?
    SpringCloud Eureka 新版本依赖
    @Autowired 与@Resource的区别
    spring 注释
    redis 的 rdb 和 aof 持久化的区别
    jdk1.7下HashMap的头插法问题
  • 原文地址:https://www.cnblogs.com/scottckt/p/1533073.html
Copyright © 2011-2022 走看看