首页 > 其他 > 详细

导出Excel 有身份证时注意

时间:2014-03-14 18:40:20      阅读:328      评论:0      收藏:0      [点我收藏+]

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:@");
        }

导出Excel 有身份证时注意,布布扣,bubuko.com

导出Excel 有身份证时注意

原文:http://www.cnblogs.com/PingleDay/p/3599032.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!