• 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做关键词搜索

    Top
    收藏
    关注
    评论
  • 相关阅读:
    javaweb学习总结(二十九)——EL表达式
    javaweb学习总结(二十)——JavaBean总结
    Js_闭包详解
    JDBC各种数据库连接URL关键代码
    Jquery Table 的基本操作
    浅谈HTTP中Get与Post的区别
    hibernate一级缓存和二级缓存的区别
    SQL删除重复数据只保留一条
    数据库事务的隔离级别
    完全卸载oracle11g
  • 原文地址:https://www.cnblogs.com/alanjl/p/3423140.html
Copyright © 2020-2023  润新知