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

     /// <summary>
            /// 导出excel
            /// </summary>
            /// <param name="gv">gridview控件名称</param>
            /// <param name="FileName">要保存的文件名字</param>
            public static void DumpExcel(GridView gv, string FileName)
            {
                string style = @"<style> .text {  } </script>";
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.Charset = "GB2312";
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
                HttpContext.Current.Response.ContentType = "application/excel";
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw); gv.RenderControl(htw);
                // Style is added dynamically
                HttpContext.Current.Response.Write(style);
                HttpContext.Current.Response.Write(sw.ToString());
                HttpContext.Current.Response.End();
            }

    样式在gridview里面写好,例如边框是否居中

  • 相关阅读:
    原创 动态卷积
    BZOJ1565 植物大战僵尸
    BZOJ1143 [CTSC2008] 祭祀river
    BZOJ3438 小M的作物
    BZOJ3144 [HNOI2013]切糕
    BZOJ2039 [2009国家集训队]employ人员雇佣
    BZOJ1066[SCOI2007]蜥蜴
    BZOJ3874 codevs3361 宅男计划
    Codeforces Round #343 (Div. 2)
    [转]后缀自动机(SAM)
  • 原文地址:https://www.cnblogs.com/liziqiang/p/3435487.html
Copyright © 2011-2022 走看看