zoukankan      html  css  js  c++  java
  • Gridview导出excel

        protected void Button_ServerClick(object sender, EventArgs e)
        {
            Excel ExportExcel = new Excel();
            string Year = System.DateTime.Now.Year.ToString();
            string Month = System.DateTime.Now.Month.ToString();
            string Day = System.DateTime.Now.Day.ToString();
            string DateString = Year + "-" + Month + "-" + Day;
            ExportExcel.Generate("DangAn", DateString, GridView1);
        }

        public override void VerifyRenderingInServerForm(Control control)
        {
            (必须有)
                //base.VerifyRenderingInServerForm(control);
        }

        public void Generate(string Typename, string scswId, GridView TempGrid)
        {

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Charset = "utf-8";
            string Filename = Typename + scswId + ".xls";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "online;filename=" + Filename);
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            TempGrid.RenderControl(oHtmlTextWriter);
            HttpContext.Current.Response.Write(oStringWriter.ToString());
            HttpContext.Current.Response.End();
        }

  • 相关阅读:
    你要结婚了丶
    20150806这是个悲伤的日子。
    今天是我的生日。
    这是从word发的第一篇博客。
    【关于JavaScript】自动计算的实例
    【关于JavaScript】常见表单用户名、密码不能为空
    【关于php】Appserv中关于DW配置站点问题
    【关于php】Appserv的安装注意事项
    【无题】写在5月18日
    HTML中如何添加日历插件(JQUERY)
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/534081.html
Copyright © 2011-2022 走看看