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();
        }


  • 相关阅读:
    Vue的条件渲染详解
    Vue的style绑定
    Vue的class绑定总结
    v-model详解
    MUI手势锁
    mysql主从搭建
    处理绿盟科技安全评估的系统漏洞
    微信小程序发送ajax
    微信小程序上拉下拉刷新
    微信小程序覆盖自定义组件样式
  • 原文地址:https://www.cnblogs.com/scottckt/p/1533073.html
Copyright © 2011-2022 走看看