zoukankan      html  css  js  c++  java
  • 导出Excel 有身份证时注意

    if (this.GridView1.Rows.Count != 0)
                {
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");     //这里是用日期做名称
                    HttpContext.Current.Response.Charset = "utf-8";
                    HttpContext.Current.Response.ContentType = "application/excel";
                    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                    this.GridView1.AllowPaging = false;                 //GridView不启用分页
                    GridView1.RenderControl(htmlWrite);
                    HttpContext.Current.Response.Write(stringWrite.ToString());
                }

    如果你的 GridView 中有 【身份证号】 那你就要注意喽!将身份证号那一列设置为以下这种格式,就OK拉!

    for (int i = 1; i <= GridView1.Rows.Count; i++)
            {
                GridView1.Rows[i - 1].Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                GridView1.Rows[i - 1].Cells[18].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
            }

  • 相关阅读:
    分布式文件系统:HDFS
    MapReduce处理流程
    Maven之pom知识点
    Junit单元测试
    Mybatis中@param注解
    kafka在Maven项目中的使用
    无线/安卓安全课堂内容
    C中经常忘记的一些东西
    基于七牛API开发的前端JavaScript SDK
    常见名词解释
  • 原文地址:https://www.cnblogs.com/PingleDay/p/3599032.html
Copyright © 2011-2022 走看看