Gridview数据导出excel时身份证号码为科学计数法的解决方法

  if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string id = this.GridView1.DataKeys[e.Row.RowIndex]["id"].ToString();
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                ((LinkButton)e.Row.Cells[2].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除此记录吗?')");
            }
            e.Row.Cells[1].Text = String.Format("<a  href='javascript:Targetedit({0});'>编辑</a>", id);
            e.Row.Cells[5].Attributes.Add("style", "vnd.ms-excel.numberformat:@;");  //保证导出excel不会已科学计数法显示
           // e.Row.Cells[4].Attributes.Add("style", "vnd.ms-excel.numberformat:@;");
        }

  

通常在Gridview中将数据导出为excel时,身份证号码常常被以科学计数法显式,影响导出的正确性,经过在网上查找资料,发现用下面的方法可以解决这种问题

在gridview的rowdatabound事件中写下面的代码

if (e.row.rowtype=datacontrolrowtype.datarow) then

    e.row.cell(i).attributes.add("style","vnd.ms-excel.numberformat:@;")

end  if

  

 

其中i为身份证号码的那一列,数的时候从0开始,其实也就是加了个格式,更多的解答请用vnd.ms-excel.numberformat做关键词搜索

转载于:https://www.cnblogs.com/alanjl/p/3423140.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值