zoukankan      html  css  js  c++  java
  • gridview操作excel导出时解决显示成科学计数法的问题

    对单元格数据进行格式化:

    常见的格式如下: (除文本格式测试通过外,日期好像不行,其他未测试)

    1) 文本:vnd.ms-excel.numberformat:@
    2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
    3) 数字:vnd.ms-excel.numberformat:#,##0.00
    4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
    5) 百分比:vnd.ms-excel.numberformat: #0.00%

    代码
    1 protected void GVExport_RowDataBound(object sender, GridViewRowEventArgs e)
    2 {

    8 if( e.Row.RowIndex > -1 )
    9 {
    10 //for (int i = 0; i < e.Row.Cells.Count; i++)
    11 //{
    12 // e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
    13 //}
    14   e.Row.Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
    15 e.Row.Cells[2].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
    16 //e.Row.Cells[17].Attributes.Add("style", "vnd.ms-excel.numberformat:yyyy/mm/dd");
    20   }
    21 }

     实在不行,再加上如下操作试试,在导出excel的方法中加上如下代码:

    代码
    1 System.Web.UI.WebControls.GridView gv = new GridView();
    2 gv.RowDataBound += new System.Web.UI.WebControls.GridViewRowEventHandler(gv_ItemDataBound); //绑定格式转换方法
    3 gv.DataSource = dt.DefaultView;
    4 gv.DataBind();
    5
  • 相关阅读:
    弱口令扫描.python脚本
    扫描web目录的Python小脚本
    Linux /etc目录重要文件
    linux(centos7)系统优化
    泛型程序设计
    对象包装器与自动装箱
    打包apk时,提示:error: Error: Resource is not public.
    SpringMVC分页实现
    IDEA搭建基于maven 的SSM框架
    ssm框架搭建
  • 原文地址:https://www.cnblogs.com/pfs1314/p/1699314.html
Copyright © 2011-2022 走看看